Skip to content

Commit

Permalink
feat!: upgrade to Archway v6 (#114)
Browse files Browse the repository at this point in the history
### Added

#### **arch3-core**

- added `withdrawToWallet` property to the `ContractMetadata` interface

### Changed

#### **arch3-proto**

- updated to the version `6.0.0` of the protocol
  • Loading branch information
eliasmpw authored Feb 6, 2024
1 parent 87fcd20 commit 1ceca20
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 41 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/arch3-core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/arch3-core/src/archwayclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
77 changes: 54 additions & 23 deletions packages/arch3-core/src/signingarchwayclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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();
});
});
});
});
3 changes: 3 additions & 0 deletions packages/arch3-core/src/signingarchwayclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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,
},
};
}
Expand Down
5 changes: 5 additions & 0 deletions packages/arch3-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
20 changes: 18 additions & 2 deletions packages/arch3-proto/generated/archway/rewards/v1/rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -180,7 +186,8 @@ function createBaseContractMetadata(): ContractMetadata {
return {
contractAddress: "",
ownerAddress: "",
rewardsAddress: ""
rewardsAddress: "",
withdrawToWallet: false
};
}
export const ContractMetadata = {
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -223,21 +236,24 @@ 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 {
const obj: any = {};
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>): ContractMetadata {
const message = createBaseContractMetadata();
message.contractAddress = object.contractAddress ?? "";
message.ownerAddress = object.ownerAddress ?? "";
message.rewardsAddress = object.rewardsAddress ?? "";
message.withdrawToWallet = object.withdrawToWallet ?? false;
return message;
}
};
Expand Down
7 changes: 5 additions & 2 deletions packages/arch3-proto/generated/archway/rewards/v1/tx.amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface MsgSetContractMetadataAminoType extends AminoMsg {
contract_address: string;
owner_address: string;
rewards_address: string;
withdraw_to_wallet: boolean;
};
};
}
Expand Down Expand Up @@ -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
}
};
},
Expand All @@ -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
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/arch3-proto/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/arch3-proto/proto/archway/rewards/v1/rewards.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions scripts/start-local-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 |
Expand All @@ -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 | \
Expand Down
Loading

0 comments on commit 1ceca20

Please sign in to comment.