Skip to content

Commit

Permalink
mow full test. non compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
funderbrker committed Mar 4, 2024
1 parent 66cbf37 commit 218f22e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion projects/sdk/src/lib/tractor/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const RATIO_FACTOR = ethers.BigNumber.from(10).pow(18);

// Create a Blueprint to Mow the publishers stalk.
// This function represents only one approach to implement a Mow Blueprint and is inherently biased.
function createBlueprint_mow(publisher: string) {
export function createBlueprint_mow(publisher: string) {
const rewardRatio = RATIO_FACTOR.div(100); // 1%

const blueprint: Blueprint = <Blueprint>{
Expand Down
24 changes: 24 additions & 0 deletions projects/sdk/src/lib/tractor/tractor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This test uses the Tractor SDK and core Tractor code. It represents how an end user would interact with Tractor.

import { ethers } from "ethers";
import { Blueprint, Requisition } from "./types";
import { createBlueprint_mow } from "./examples";
import { Tractor } from "./tractor";
import { getTestUtils } from "src/utils/TestUtils/provider";

const { sdk, account, utils } = getTestUtils();

describe("tractor mow", async () => {
it("throws if tractor operate fails", async () => {
let publisher: ethers.Wallet = ethers.Wallet.createRandom();
const blueprint: Blueprint = createBlueprint_mow(publisher.address);
const blueprintHash: string = await Tractor.getBlueprintHash(blueprint);
const requisition: Requisition = {
blueprint: blueprint,
blueprintHash: blueprintHash,
signature: await publisher.signMessage(blueprintHash)
};

await sdk.contracts.beanstalk.runBlueprint(requisition).then((txn) => txn.wait());
});
});
25 changes: 22 additions & 3 deletions projects/sdk/src/lib/tractor/tractor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BeanstalkSDK } from "../BeanstalkSDK";
import { ethers, ContractTransaction } from "ethers";
import { Requisition, Bytes } from "./types";
import { Blueprint, Requisition } from "./types";

export class Tractor {
static sdk: BeanstalkSDK;
Expand All @@ -9,16 +9,35 @@ export class Tractor {
// operator: Operator;
// sequenceBuilder: OperatorDataBuilder;


constructor(sdk: BeanstalkSDK) {
Tractor.sdk = sdk;
// this.sequenceBuilder = new SequenceBuilder(sdk);
// this.operator = new Operator(sdk);
// this.publisher = new Publisher(sdk);
}

static async getBlueprintHash(blueprint: Blueprint): Promise<string> {
return Tractor.sdk.contracts.beanstalk.interface.getBlueprintHash(blueprint);
}

// async signRequisition(requisition: Requisition, signer: ethers.Signer) {
// // Ethers treats hash as an unexpectedly encoded string, whereas solidity signs hash as bytes. So arrayify here.
// requisition.signature = await signer.signMessage(
// ethers.utils.arrayify(requisition.blueprintHash)
// );
// }

// async composeBlueprintData() {}

// async composeBlueprintOperatorPasteInstrs() {}

// async encodeData() {}

// encode;

// async encodeOperatorData() {}

async tractor(requisition: Requisition, operatorData: Bytes): Promise<ContractTransaction> {
return Tractor.sdk.contracts.beanstalk.tractor(requisition, operatorData);
}

}
18 changes: 11 additions & 7 deletions projects/sdk/src/lib/tractor/types.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { ethers } from "ethers";

export type uint80 = number;
export type uint80 = ethers.BigNumber;

export type Blueprint = {
publisher: string;
data: ethers.Bytes;
operatorPasteInstrs?: ethers.Bytes;
operatorPasteInstrs: ethers.Bytes;
maxNonce: ethers.BigNumber;
startTime: ethers.BigNumber;
endTime: ethers.BigNumber;
};

export type Requisition = {
blueprint: Blueprint;
blueprintHash: ethers.Bytes;
signature: ethers.Bytes;
blueprintHash: string;
signature: string;
};

export type Draft = {
advFarmCalls: AdvancedFarmCall[];
// export type Draft = {
// actions: DraftAction[];
// };

export type DraftAction = {
farmCall: AdvancedFarmCall;
operatorPasteInstrs: OperatorPasteInstr[];
};

export type AdvancedFarmCall = {
callData: ethers.Bytes;
clipboard: ethers.Bytes;
clipboard: string;
};

export type OperatorPasteInstr = {
Expand Down

0 comments on commit 218f22e

Please sign in to comment.