Skip to content

Commit

Permalink
2068 support drain delegate operation in contract api (#2183)
Browse files Browse the repository at this point in the history
* 2073 support type ticket deprecated in michelson encoder (#2094)

* feat: exposed setParserProvider configuration through TezosToolkit

re #660

* test: added integration tests using setParserProvider with TezosToolkit

re #660

* docs: updated starting production server commands with taquito-test-dapp readme.md

* test: removed unnecessory console.log

re #660

* chore: update vite to latest version

* docs: fixed some typos in doc to address comments

re #660

* 1630 ballot operation support in contract API (#2050)

* added estimate and contract ballot operation support

* added rpc contract provider for ballot op

* updated implementation and added docs

* added property in OperationContentsAndResultBallot and added unit test

* remove metadata property from ballot

* addressed PR comments

* updated yarn and package-lock

* cleaned up comments and switched out async for promise in op emitter

* removed unnecessary line break

* 660 support customize parser options (#2061)

* feat: exposed setParserProvider configuration through TezosToolkit

re #660

* test: added integration tests using setParserProvider with TezosToolkit

re #660

* docs: updated starting production server commands with taquito-test-dapp readme.md

* test: removed unnecessory console.log

re #660

* chore: update vite to latest version

* docs: fixed some typos in doc to address comments

re #660

* feat(n): support type ticket_deprecated in michelson encoder

re #2073

* contract-security-non-existent-KT-address: use rpc (#2091)

* fix: address comment with TicketDeprecatedEncodeError and fix unit tests

fix #2073

Co-authored-by: Davis Sawali <[email protected]>
Co-authored-by: Arvid Jakobsson <[email protected]>
Co-authored-by: Roxane Létourneau <[email protected]>

* Deprecate Tezbridge (#2105)

* 1630 ballot operation support in contract API (#2050)

* added estimate and contract ballot operation support

* added rpc contract provider for ballot op

* updated implementation and added docs

* added property in OperationContentsAndResultBallot and added unit test

* remove metadata property from ballot

* addressed PR comments

* updated yarn and package-lock

* cleaned up comments and switched out async for promise in op emitter

* removed unnecessary line break

* 660 support customize parser options (#2061)

* feat: exposed setParserProvider configuration through TezosToolkit

re #660

* test: added integration tests using setParserProvider with TezosToolkit

re #660

* docs: updated starting production server commands with taquito-test-dapp readme.md

* test: removed unnecessory console.log

re #660

* chore: update vite to latest version

* docs: fixed some typos in doc to address comments

re #660

* refactor: deprecate tezbridge and related

* contract-security-non-existent-KT-address: use rpc (#2091)

* refactor: deprecate tezbridge and related

Co-authored-by: Davis Sawali <[email protected]>
Co-authored-by: hui-an-yang <[email protected]>
Co-authored-by: Arvid Jakobsson <[email protected]>
Co-authored-by: Roxane Létourneau <[email protected]>

* 2064 lima integration remove jakarta (#2084)

* 1630 ballot operation support in contract API (#2050)

* added estimate and contract ballot operation support

* added rpc contract provider for ballot op

* updated implementation and added docs

* added property in OperationContentsAndResultBallot and added unit test

* remove metadata property from ballot

* addressed PR comments

* updated yarn and package-lock

* cleaned up comments and switched out async for promise in op emitter

* removed unnecessary line break

* 660 support customize parser options (#2061)

* feat: exposed setParserProvider configuration through TezosToolkit

re #660

* test: added integration tests using setParserProvider with TezosToolkit

re #660

* docs: updated starting production server commands with taquito-test-dapp readme.md

* test: removed unnecessory console.log

re #660

* chore: update vite to latest version

* docs: fixed some typos in doc to address comments

re #660

* initial changes, check chainids

adjust config, run originate contracts

 add untracked

fix improper config data

switch jakarta tests, switch rpc endpoint

fix missed jakartanet

adjust constants lima, estimate test values

fix broken value

* change test protocol runs

Co-authored-by: Davis Sawali <[email protected]>
Co-authored-by: hui-an-yang <[email protected]>
Co-authored-by: Zainen Suzuki <[email protected]>

* 2069 type changes (#2114)

* updated types for lima

* update constants.ts with protocol hash for lima

* updated unit tests

* changed test name for clarity

* addressed PR comments

* 2066 support types for new operations in lima (#2097)

* feat: support new types for new operations UpdateConsensusKey and DrainDelegate in Lima

re #2066

* test: update_consensus_key unit test added for limanet

re #2066

* test: added drain_deleagte unit test for limanet

re #2066

* test: minor fix rpc-response data and updateConsensusKey unit test

re #2066

* test: addressed comments to update correct test title

re #2066

* Replace lima rpc url in test

* added new rpc endpoints and updated tests (#2148)

* added new rpc endpoints and updated tests

* updated unit tests

* updated unit test for rpc-cache

* updated typedoc and updated test to originate own contract

* 2065 local forging support new operations for lima 2 (#2139)

* feat: support new types for new operations UpdateConsensusKey and DrainDelegate in Lima

re #2066

* test: update_consensus_key unit test added for limanet

re #2066

* feat: support new operation UpdateConsensusKey for Lima

re #2065

* feat: support new operation updateConsensusKey in local-forger for Lima

re #2065

* revert: removed unnecesorry change of updateConsensusKey in rpc-batch-provider

re #2065

* revert: changes of update_consensus_key in RpcContractProvider and RPCEstimateProvider

re #2065

* feat: support new operation drainDelegate for Lima

re #2065

* feat: support new encoding for ticket & ticket depreacted in lima with tests

re #2072

* fix: added ASSERT_SOME in ticketCode and fixed 2 integration tests in lima

re #2072

* fix: fixs merge conflicts

* fix: replaced ASSERT_SOME with its expansion in ticketCode

re #2072

* test: added local-forgin integration tests for new operations

re #2065

* fix: address comments removed duplicate tests and move kathcases to commoncases

re #2065

* fix: address comments to remove kathcases integration tests

re #2065

* test: address comments add forge and parse operation test suite back with lima cases

re #2065

* test: addressing comments updated file name and added simicolons

re #2065

* test: address comments added semicolon

re #2065

* fix: configure localforger with lima protocol hash with lima cases

re #2065

* fix: removed update_consensus_key & drain_delegate from encodersProto14 and decoderProto14

re #2065

* feat: removed Jakarta conditions in on chain view related files (#2138)

re #2098

* fix(local-forging): fix encoding for deposit entrypoint (#2160)

* fix(local-forging): fix encoding for deposit entrypoint

In lima protocol, the %deposit entrypoint is now represented by 0x05

fix #2158

* Fix unit tests

* Fix tests kathmandunet

* 2071 lima rpc changes (#2095)

* initial changes, check chainids

adjust config, run originate contracts

 add untracked

fix improper config data

switch jakarta tests, switch rpc endpoint

fix missed jakartanet

adjust constants lima, estimate test values

fix broken value

fix constants test add minimum_stake to replace tokens_per_roll

fix ticket_token type

fix constants expects

correct ticket updates type, todo add test

corrections, add proto015 mock data

add sample && unit test for ticket_updates

* resolve error for test

* fix tests improper values

* pr comments so far

* update tests for all testnets

* missed test cahnge

* remove yarn lock, fix missed spot

* remove quotes

* initial changes, check chainids

adjust config, run originate contracts

 add untracked

fix improper config data

switch jakarta tests, switch rpc endpoint

fix missed jakartanet

adjust constants lima, estimate test values

fix broken value

fix constants test add minimum_stake to replace tokens_per_roll

fix ticket_token type

fix constants expects

correct ticket updates type, todo add test

corrections, add proto015 mock data

add sample && unit test for ticket_updates

resolve error for test

fix tests improper values

pr comments so far

update tests for all testnets

missed test cahnge

remove yarn lock, fix missed spot

remove quotes

pr comments

* fix ticket_receipt

* remove duplication after mondaynet removal from tx-rollup test

* fix rebase change

Co-authored-by: Zainen Suzuki <[email protected]>
Co-authored-by: Zainen Suzuki <[email protected]>

* fix(integration-tests): fix tests for lima

* test(integration-test): fix contract-tx-rollup-origination-operation test for flextesa

Bump storage_limit because the constant tx_rollup_origination_size is set to an higher value on
flextesa than on the testnets

* test(michel-codec): added lima contracts for unit tests

There is no code change in the branch. I removed the contracts related to protocols 10 to 13 and
added contracts for the protocol 15. Some contracts are commented out in the contract_015.spec.ts
file as they are currently failing. Those contracts should be uncommented and fixed when working on
the issue #2075.

re $2075

* 2074 local forging support new instruction lambda rec (#2159)

* test: added code_with_lambda_rec file and test against rpc forger

re #2074

* fix: added LAMBDA_REC condition padding in primEncoder and primDecoder

re #2074

* style: linted lambdaRecCode

re #2074

* test(integration-test): lambda_rec

Deploy a contract written in plain michelson that contains the LAMBDA_REC instruction (test
michel-codec and local-forging support of LAMBDA_REC inst). Call a contract having the type lambda
in its entrypoint by passing a recursive lambda (test michelson-encoder package and local-forging
package).

* feat: support drain_delegate operation in contract api

re #2068

* fix: fix drain_delegate bugs in contract api

re #2068

* test: added unit test for drain_delegate in contract api

re #2068

* test(integration-test): fixed tx-rollup-l2-address test for limanet (#2171)

* test(integration-test): fixed tx-rollup-l2-address test for limanet

For the lima protocol, the instruction TICKET needs to be followed by ASSERT_SOME

fix #2170

* Removed console.log

* fix(rpc): add missing properties related to lima

fix #2172

* add tests for parsing mode for all testnets, and fail case (#2184)

* add tests for parsing mode for all testnets, and fail case

* one more test fail

* format

Co-authored-by: Zainen Suzuki <[email protected]>

* test(integration-test): small clean up and remove duplication

* 2075 lambda rec michel codec (#2175)

* parent 8922de6
author Zainen Suzuki <[email protected]> 1666748308 -0700
committer Zainen Suzuki <[email protected]> 1670007819 -0800

initial changes, check chainids

adjust config, run originate contracts

 add untracked

fix improper config data

switch jakarta tests, switch rpc endpoint

fix missed jakartanet

adjust constants lima, estimate test values

fix broken value

fix constants test add minimum_stake to replace tokens_per_roll

fix ticket_token type

fix constants expects

correct ticket updates type, todo add test

corrections, add proto015 mock data

add sample && unit test for ticket_updates

fix tests improper values

update tests for all testnets

missed test cahnge

initial work retstack still broken

passing without validation

add other contract

add contracts and setup

comment out

all test passing. binanry.spec.ts failing values

fix binary array sensitive order

remove unneeded

more cleanup

Lambda_rec michelsonData addition

remove duplicate

change to instructionlist

* feat(michel-codec): pack/unpack Lambda_rec data

fix #2181

* remove commented

Co-authored-by: Zainen Suzuki <[email protected]>
Co-authored-by: roxaneletourneau <[email protected]>

* Try fix test

* Implemented update_consensus_key support in Contract API (#2179)

* Implemented update_consensus_key support in Contract API and updated tests

* addressed PR comments

* chore(releng) bump version to 15.0.0-beta-RC.0

* test: added integraiton test of drain_delegate

re #2068

* Adapt integration tests to limanet box

* Missing flextesa mini-net command

* docs: added documentation for drain delegate operation

re #2068

* docs: updated docs

* build: fixs docker command for flextesa-lima

* docs: added docs for drain delegate op

re #2068

* build: fixs docker command for flextesa-lima

* build: fixs docker command for flextesa-lima

* test: updated working drain delegate integration test

re #2068

* test: updated sandbox file names in integration tests

re #2068

* docs: removed duplicate doc

re #2068

* chore: removed unused package-lock.json

re #2068

* build: fixs flextesa-lima ci command

* build: removed uneeded bit

re #2068

* chore: removed extra sandbox-env file

* chore: revert the last change

* test: updated rpc check to be localhost

* fix: addressed pr comments and update testdapp to reasonable gaslimit

re #2068

* pull master changes

* fix: address comments and add skip test condition based on protocol

re #2068

* style: address comment to be consistent  wtih camel case

re #2068

Co-authored-by: Davis Sawali <[email protected]>
Co-authored-by: Arvid Jakobsson <[email protected]>
Co-authored-by: Roxane Létourneau <[email protected]>
Co-authored-by: Edward Garson <[email protected]>
Co-authored-by: Zainen <[email protected]>
Co-authored-by: Zainen Suzuki <[email protected]>
Co-authored-by: roxaneletourneau <[email protected]>
Co-authored-by: Zainen Suzuki <[email protected]>
Co-authored-by: Daniele Lisi <[email protected]>
  • Loading branch information
10 people authored Dec 15, 2022
1 parent fe7cf1c commit 77ea05d
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/taquito-test-dapp/src/lib/TestContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let loading = false;
let success: boolean | undefined;
let opHash = "";
let input = { text: "", fee: 400, storageLimit: 400, gasLimit: 4000 };
let input = { text: "", fee: 400, storageLimit: 400, gasLimit: 1320 };
let testResult: { id: string; title: string; body: any };
const run = async () => {
Expand Down
19 changes: 18 additions & 1 deletion docs/consensus_key.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Consensus Keys
author: Davis Sawali
author: Davis Sawali & Hui-An Yang
---

The "consensus key" feature allows bakers to use a different key, called the consensus key. It will allow for baking and signing consensus operations (i.e. pre-endorsements and endorsements). For more detailed information on consensus keys, refer to [this documentation](https://tezos.gitlab.io/protocols/015_lima.html?highlight=update%20consensus%20key#consensus-key)
Expand All @@ -20,3 +20,20 @@ await op.confirmation();
```
- `pk` is the public key you want the consensus key to point to


## Drain Delegate
This is an operation that must be signed by the active consensus key `consensus_pkh` of the baker `baker_pkh`. This operation immediately transfers all the spendable balance of the `baker_pkh`’s implicit account into the `destination_pkh` implicit account. It has no effect on the frozen balance. This operation is included in pass 2 (anonymous operations). So drain operations don’t compete with regular manager operations for gas and block size quota; the 1M restriction (one-operation-per-manager-per-block) applies to drain operations as well, meaning that a drain for a baker and a transfer operation from the same baker are in conflict. As an incentive for bakers to include drain operations, a fixed fraction of the drained baker’s spendable balance is transferred as fees to the baker that includes the operation, i.e. the maximum between 1tz or 1% of the spendable balance.

### Examples
```typescript
const drain = await Tezos.contract.drainDelegate({
consensus_key: 'CONSENSUS_PKH',
delegate: 'BAKER_PKH',
destination: 'DESTINATION_PKH',
});
await drain.confirmation();
```

- `consensus_key` is the public key hash of the updated consensus key
- `delegate` is the public key hash of the baker/delegate
- `destination` is the public key hash of the destination account
60 changes: 60 additions & 0 deletions integration-tests/sandbox-drain-delegate-operation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { TezosToolkit, Protocols } from "@taquito/taquito";
import { CONFIGS, sleep } from "./config";

CONFIGS().forEach(({ lib, protocol, rpc, setup, createAddress }) => {
const Tezos = lib;
const flextesanet = (protocol === Protocols.PtLimaPtL || protocol === Protocols.ProtoALpha) && rpc === 'http://localhost:20000' ? test : test.skip;

describe(`Test Drain Delegate using: ${rpc}`, () => {
let Delegate: TezosToolkit;
let delegatePkh: string;
let Destination: TezosToolkit;
let destinationPkh: string;
beforeAll(async (done) => {
await setup(true);

try {
Delegate = await createAddress();
delegatePkh = await Delegate.signer.publicKeyHash();;
Destination = await createAddress();
destinationPkh = await Destination.signer.publicKeyHash();

// fund the delegate
const transferOp = await Tezos.contract.transfer({ to: delegatePkh, amount: 5 });
await transferOp.confirmation();

// register as delegate
const registerOp = await Delegate.contract.registerDelegate({});
await registerOp.confirmation();

// update consensus key to destination
const updateOp = await Delegate.contract.updateConsensusKey({ pk: await Destination.signer.publicKey() });
await updateOp.confirmation();

// wait for more than preserved_cycles + 1 for consensus_key to be active
const constants = await Delegate.rpc.getConstants();
await sleep(((constants.preserved_cycles + 2) * constants.blocks_per_cycle * (constants.minimal_block_delay!.toNumber())) * 1000);

} catch(e) {
console.log(JSON.stringify(e));
}
done();
})
flextesanet('Should be able to inject drain_delegate operation', async (done) => {
expect((await Delegate.rpc.getBalance(delegatePkh)).toNumber()).toBeGreaterThan(0);
let destinationBalanceBefore = (await Destination.rpc.getBalance(destinationPkh)).toNumber();

const drainOp = await Destination.contract.drainDelegate({
consensus_key: destinationPkh,
delegate: delegatePkh,
destination: destinationPkh,
});
await drainOp.confirmation();

expect(drainOp.includedInBlock).toBeDefined()
expect((await Delegate.rpc.getBalance(delegatePkh)).toNumber()).toEqual(0);
expect((await Destination.rpc.getBalance(destinationPkh)).toNumber()).toBeGreaterThan(destinationBalanceBefore);
done();
});
});
})
4 changes: 2 additions & 2 deletions integration-tests/sandbox-env.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
export RUN_KATHMANDUNET_WITH_SECRET_KEY=true
export RUN_LIMANET_WITH_SECRET_KEY=true
export SECRET_KEY=edsk3RFgDiCt7tWB2oe96w1eRw72iYiiqZPLu9nnEY23MYRp2d8Kkx
export TEZOS_RPC_KATHMANDUNET=http://localhost:20000
export TEZOS_RPC_LIMANET=http://localhost:20000
export POLLING_INTERVAL_MILLISECONDS=100
export RPC_CACHE_MILLISECONDS=0
export TEZOS_BAKER=tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
12 changes: 12 additions & 0 deletions packages/taquito/src/contract/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TxRollupBatchParams,
IncreasePaidStorageParams,
TransferTicketParams,
DrainDelegateParams,
BallotParams,
ProposalsParams,
UpdateConsensusKeyParams,
Expand All @@ -28,6 +29,7 @@ import { ContractAbstraction, ContractStorageType, DefaultContractType } from '.
import { TxRollupBatchOperation } from '../operations/tx-rollup-batch-operation';
import { IncreasePaidStorageOperation } from '../operations/increase-paid-storage-operation';
import { TransferTicketOperation } from '../operations/transfer-ticket-operation';
import { DrainDelegateOperation } from '../operations';
import { BallotOperation } from '../operations';
import { ProposalsOperation } from '../operations/proposals-operation';
import { UpdateConsensusKeyOperation } from '../operations/update-consensus-key-operation';
Expand Down Expand Up @@ -221,6 +223,16 @@ export interface ContractProvider extends StorageProvider {
*/
txRollupSubmitBatch(params: TxRollupBatchParams): Promise<TxRollupBatchOperation>;

/**
*
* @description Submit a drain delegate operation
*
* @returns An operation handle with the result from the RPC node
*
* @param DrainDelegateParams DrainDelegate operation parameter
*/
drainDelegate(params: DrainDelegateParams): Promise<DrainDelegateOperation>;

/**
*
* @description Submit ballot for an ongoing proposal
Expand Down
15 changes: 15 additions & 0 deletions packages/taquito/src/contract/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
RPCTransferTicketOperation,
IncreasePaidStorageParams,
RPCIncreasePaidStorageOperation,
DrainDelegateParams,
RPCDrainDelegateOperation,
BallotParams,
RPCBallotOperation,
ProposalsParams,
Expand Down Expand Up @@ -271,6 +273,19 @@ export const createIncreasePaidStorageOperation = async ({
} as RPCIncreasePaidStorageOperation;
};

export const createDrainDelegateOperation = async ({
consensus_key,
delegate,
destination,
}: DrainDelegateParams) => {
return {
kind: OpKind.DRAIN_DELEGATE,
consensus_key,
delegate,
destination,
} as RPCDrainDelegateOperation;
};

export const createBallotOperation = async ({ source, proposal, ballot }: BallotParams) => {
return {
kind: OpKind.BALLOT,
Expand Down
23 changes: 22 additions & 1 deletion packages/taquito/src/contract/rpc-contract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
TxRollupBatchParams,
TransferTicketParams,
IncreasePaidStorageParams,
DrainDelegateParams,
BallotParams,
ProposalsParams,
UpdateConsensusKeyParams,
Expand All @@ -43,6 +44,7 @@ import {
createTxRollupBatchOperation,
createTransferTicketOperation,
createIncreasePaidStorageOperation,
createDrainDelegateOperation,
createBallotOperation,
createProposalsOperation,
createUpdateConsensusKeyOperation,
Expand All @@ -60,7 +62,8 @@ import { TxRollupOriginationOperation } from '../operations/tx-rollup-originatio
import { TxRollupBatchOperation } from '../operations/tx-rollup-batch-operation';
import { TransferTicketOperation } from '../operations/transfer-ticket-operation';
import { IncreasePaidStorageOperation } from '../operations/increase-paid-storage-operation';
import { BallotOperation } from '../operations';
import { BallotOperation } from '../operations/ballot-operation';
import { DrainDelegateOperation } from '../operations/drain-delegate-operation';
import { ProposalsOperation } from '../operations/proposals-operation';
import { UpdateConsensusKeyOperation } from '../operations/update-consensus-key-operation';

Expand Down Expand Up @@ -530,6 +533,24 @@ export class RpcContractProvider
);
}

/**
*
* @description Transfers the spendable balance of the delegate to destination when consensus_key is the active consensus key of delegate
*
* @returns An operation handle with the result from the rpc node
*
* @param params drainDelegate operation parameter
*/
async drainDelegate(params: DrainDelegateParams) {
const operation = await createDrainDelegateOperation({
...params,
});
const prepared = await this.prepareOperation({ operation: operation });
const opBytes = await this.forge(prepared);
const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
return new DrainDelegateOperation(hash, operation, forgedBytes, opResponse, context);
}

/**
*
* @description Originate a new tx rollup. Will sign and inject an operation using the current context
Expand Down
45 changes: 45 additions & 0 deletions packages/taquito/src/operations/drain-delegate-operation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { OperationContentsAndResult, OperationContentsAndResultDrainDelegate } from '@taquito/rpc';
import { Context } from '../context';
import { Operation } from './operations';
import { ForgedBytes, RPCDrainDelegateOperation } from './types';

/**
*
* @description DrainDelegateOperation provides utility functions to fetch a new operation of kind drain_delegate
*
*/

export class DrainDelegateOperation extends Operation {
constructor(
hash: string,
private readonly params: RPCDrainDelegateOperation,
raw: ForgedBytes,
results: OperationContentsAndResult[],
context: Context
) {
super(hash, raw, results, context);
}

get operationResults() {
const drainDelegateOp =
Array.isArray(this.results) &&
(this.results.find(
(op) => op.kind === 'drain_delegate'
) as OperationContentsAndResultDrainDelegate);
const result =
drainDelegateOp && drainDelegateOp.metadata && drainDelegateOp.metadata.balance_updates;
return result ? result : undefined;
}

get consensusKey() {
return this.params.consensus_key;
}

get delegate() {
return this.params.delegate;
}

get destination() {
return this.params.destination;
}
}
3 changes: 3 additions & 0 deletions packages/taquito/src/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export {
RPCActivateOperation,
RPCOperation,
PrepareOperationParams,
DrainDelegateParams,
RPCDrainDelegateOperation,
BallotParams,
RPCBallotOperation,
} from './types';
Expand All @@ -35,4 +37,5 @@ export { DelegateOperation } from './delegate-operation';
export { OriginationOperation } from './origination-operation';
export { TransactionOperation } from './transaction-operation';
export { BallotOperation } from './ballot-operation';
export { DrainDelegateOperation } from './drain-delegate-operation';
export { Operation } from './operations';
1 change: 1 addition & 0 deletions packages/taquito/src/operations/operation-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export abstract class OperationEmitter {
cOps.map((op: RPCOperation) => {
switch (op.kind) {
case OpKind.ACTIVATION:
case OpKind.DRAIN_DELEGATE:
return {
...op,
};
Expand Down
20 changes: 20 additions & 0 deletions packages/taquito/src/operations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,25 @@ export interface RPCIncreasePaidStorageOperation {
destination: string;
}

/**
* @description Parameters for the DrainDelegate method
*/
export interface DrainDelegateParams {
consensus_key: string;
delegate: string;
destination: string;
}

/**
* @description RPC DrainDelegate operation
*/
export interface RPCDrainDelegateOperation {
kind: OpKind.DRAIN_DELEGATE;
consensus_key: string;
delegate: string;
destination: string;
}

/**
* @description Ballot operation params
*/
Expand Down Expand Up @@ -489,6 +508,7 @@ export type RPCOperation =
| RPCTxRollupBatchOperation
| RPCTransferTicketOperation
| RPCIncreasePaidStorageOperation
| RPCDrainDelegateOperation
| RPCBallotOperation
| RPCProposalsOperation
| RPCUpdateConsensusKeyOperation;
Expand Down
30 changes: 30 additions & 0 deletions packages/taquito/test/contract/rpc-contract-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,36 @@ describe('RpcContractProvider test', () => {
});
});

describe('drainDelegate', () => {
it('should produce a drain operation', async (done) => {
const result = await rpcContractProvider.drainDelegate({
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj',
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv',
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj',
});

expect(result.raw).toEqual({
opbytes: 'test',
opOb: {
branch: 'test',
contents: [
{
kind: 'drain_delegate',
consensus_key: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj',
delegate: 'tz1MY8g5UqVmQtpAp7qs1cUwEof1GjZCHgVv',
destination: 'tz1KvJCU5cNdz5RAS3diEtdRvS9wfhRC7Cwj',
},
],
protocol: 'test_proto',
signature: 'test_sig',
},
counter: 0,
});

done();
});
});

describe('ballot', () => {
it('should produce a ballot operation', async (done) => {
const result = await rpcContractProvider.ballot({
Expand Down
Loading

0 comments on commit 77ea05d

Please sign in to comment.