Skip to content

Commit

Permalink
wip: yield farming blaze
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Aug 16, 2024
1 parent 2825a9f commit 9be5216
Show file tree
Hide file tree
Showing 18 changed files with 1,371 additions and 37 deletions.
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
],
"lucid": [
"./dist/types/exports/lucid.d.ts"
],
"blaze": [
"./dist/types/exports/blaze.d.ts"
]
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/exports/blaze.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* ## Lucid
* ## Blaze
* Prebuilt classes for {@link Core.DatumBuilder} and {@link Core.TxBuilder} that use and depend
* on the `lucid-cardano` library. Only import these if you have also installed `lucid-cardano`
* on the `@blaze-cardano/sdk` library. Only import these if you have also installed `@blaze-cardano/sdk`
* in your main repository! Also includes a helper class for basic operations.
*
* @module Lucid
* @module Blaze
* @packageDescription
*/
export * from "../DatumBuilders/DatumBuilder.Blaze.V1.class.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/yield-farming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"docs:ci": "yarn docs --unsafe"
},
"devDependencies": {
"@blaze-cardano/emulator": "^0.1.46",
"@sundaeswap/core": "^1.2.9",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/user-event": "^14.3.0",
Expand All @@ -59,9 +60,9 @@
"typescript": "^4.6.4"
},
"peerDependencies": {
"@blaze-cardano/sdk": "^0.1.7",
"@sundaeswap/asset": "^1.0.2",
"@sundaeswap/core": "^1.1.12",
"@blaze-cardano/sdk": "^0.1.6",
"lucid-cardano": "^0.10.7"
}
}
27 changes: 27 additions & 0 deletions packages/yield-farming/src/@types/blaze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Data, Static } from "@blaze-cardano/sdk";

export const DelegationOwnerSchema = Data.Object({
address: Data.Bytes(),
});
export type TDelegationOwner = Static<typeof DelegationOwnerSchema>;
export const DelegationOwner =
DelegationOwnerSchema as unknown as TDelegationOwner;

export const DelegationProgramsSchema = Data.Array(
Data.Enum([
Data.Literal("None"),
Data.Object({
Delegation: Data.Tuple([Data.Bytes(), Data.Bytes(), Data.Integer()]),
}),
])
);
export type TDelegationPrograms = Static<typeof DelegationProgramsSchema>;
export const DelegationPrograms =
DelegationOwnerSchema as unknown as TDelegationPrograms;

export const DelegationSchema = Data.Object({
owner: DelegationOwnerSchema,
programs: DelegationProgramsSchema,
});
export type TDelegation = Static<typeof DelegationSchema>;
export const Delegation = DelegationSchema as unknown as TDelegation;
2 changes: 1 addition & 1 deletion packages/yield-farming/src/@types/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
TUTXO,
} from "@sundaeswap/core";

import { TDelegation, TDelegationPrograms } from "./contracts";
import { TDelegation, TDelegationPrograms } from "./lucid";

// /** A map of pools with their associated weight. */
// export type TDelegationProgramPools = Map<string, bigint>;
Expand Down
2 changes: 1 addition & 1 deletion packages/yield-farming/src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./configs.js";
export * from "./contracts.js";
export * from "./lucid.js";
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ global.BigInt.prototype.toJSON = function () {

import { AssetAmount } from "@sundaeswap/asset";
import { ADA_METADATA } from "@sundaeswap/core";
import { TDelegationPrograms } from "../../../@types/contracts.js";
import { TDelegationPrograms } from "../../../@types/lucid.js";
import { LockConfig } from "../LockConfig.js";

let config: LockConfig;
Expand Down
50 changes: 50 additions & 0 deletions packages/yield-farming/src/lib/classes/DatumBuilder.Blaze.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Data } from "@blaze-cardano/sdk";
import {
DatumBuilder,
TDatumResult,
TSupportedNetworks,
} from "@sundaeswap/core";
import { BlazeHelper } from "@sundaeswap/core/blaze";

import { Delegation, TDelegation } from "../../@types/blaze.js";
import { ILockArguments } from "../../@types/index.js";

/**
* The Blaze representation of a DatumBuilder. The primary purpose of this class
* is to encapsulate the accurate building of valid datums, which should be attached
* to transactions that are constructed and sent to the SundaeSwap Yield Farming V2
* smart contracts. These datums ensure accurate business logic and the conform to the
* specs as defined in the SundaeSwap smart contracts.
*/
export class DatumBuilderBlaze implements DatumBuilder {
constructor(public network: TSupportedNetworks) {}

/**
* Builds the datum for asset locking, including LP tokens and other
* native Cardano assets. There is no need to include an unlockDatum
* method, because unlock is equivalent to withdrawing all of a user's
* funds.
*/
buildLockDatum({
owner,
programs,
}: ILockArguments["delegation"]): TDatumResult<TDelegation> {
BlazeHelper.validateAddressNetwork(owner.address, this.network);
const addressDetails = BlazeHelper.getAddressHashes(owner.address);
const delegationData: TDelegation = {
owner: {
address:
addressDetails?.stakeCredentials ??
addressDetails?.paymentCredentials,
},
programs,
};

const data = Data.to(delegationData, Delegation);
return {
hash: data.hash(),
inline: data.toCbor(),
schema: delegationData,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import { LucidHelper } from "@sundaeswap/core/lucid";
import { Data } from "lucid-cardano";

import { Delegation, TDelegation } from "../../@types/contracts.js";
import { ILockArguments } from "../../@types/index.js";
import { Delegation, TDelegation } from "../../@types/lucid.js";

/**
* The Lucid representation of a DatumBuilder. The primary purpose of this class
Expand Down
Loading

0 comments on commit 9be5216

Please sign in to comment.