Skip to content

Commit

Permalink
Merge pull request #47 from SundaeSwap-finance/fix/inline-yf-migration
Browse files Browse the repository at this point in the history
chore: fix inline destination datums
  • Loading branch information
cjkoepke authored May 30, 2024
2 parents 285c3aa + 431db1a commit 54bd312
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 60 deletions.
12 changes: 6 additions & 6 deletions docs/typescript/core/classes/Lucid.DatumBuilderLucidV3.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions packages/core/src/DatumBuilders/DatumBuilder.Lucid.V3.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,32 +334,32 @@ export class DatumBuilderLucidV3 implements DatumBuilder {
public buildDestinationAddresses({
address,
datum,
}: TDestinationAddress): TDatumResult<V3Types.TDestinationDatum> {
}: TDestinationAddress): TDatumResult<V3Types.TDestination> {
LucidHelper.validateAddressAndDatumAreValid({
address: address,
datum: datum,
network: this.network,
});

const destination = LucidHelper.getAddressHashes(address);
let formattedDatum: V3Types.TDestinationDatum["datum"];
let formattedDatum: V3Types.TDestination["datum"];
switch (datum.type) {
case EDatumType.NONE:
formattedDatum = "NoDatum";
formattedDatum = new Constr(0, []);
break;
case EDatumType.HASH:
formattedDatum = { DatumHash: [datum.value] };
formattedDatum = new Constr(1, [datum.value]);
break;
case EDatumType.INLINE:
formattedDatum = { InlineDatum: [datum.value] };
formattedDatum = Data.from(datum.value);
break;
default:
throw new Error(
"Could not find a matching datum type for the destination address. Aborting."
);
}

const destinationDatum: V3Types.TDestinationDatum = {
const destinationDatum: V3Types.TDestination = {
address: {
paymentCredential: LucidHelper.isScriptAddress(address)
? {
Expand All @@ -386,7 +386,7 @@ export class DatumBuilderLucidV3 implements DatumBuilder {
datum: formattedDatum,
};

const inline = Data.to(destinationDatum, V3Types.DestinationDatum);
const inline = Data.to(destinationDatum, V3Types.Destination);

return {
hash: LucidHelper.inlineDatumToHash(inline),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("buildDestinationAddresses()", () => {
});

expect(result5.inline).toEqual(
"d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd87b9f5f5840d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457d57a22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffffffff"
"d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffff"
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("buildDestinationAddresses()", () => {
});

expect(result5.inline).toEqual(
"d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd87b9f5f5840d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457d57a22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffffffff"
"d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffff"
);

const resultWithScriptDestination =
Expand All @@ -84,7 +84,7 @@ describe("buildDestinationAddresses()", () => {
});

expect(resultWithScriptDestination.inline).toEqual(
"d8799fd8799fd87a9f581c484969d936f484c45f143d911f81636fe925048e205048ee1fe412aaffd87a80ffd87b9f5f5840d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457d57a22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffffffff"
"d8799fd8799fd87a9f581c484969d936f484c45f143d911f81636fe925048e205048ee1fe412aaffd87a80ffd8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffff"
);

const resultWithScriptDestination2 =
Expand All @@ -98,7 +98,7 @@ describe("buildDestinationAddresses()", () => {
});

expect(resultWithScriptDestination2.inline).toEqual(
"d8799fd8799fd87a9f581cd3a0d88f831105d2c1ab7ad0c31aa33bdeaa6c2503d2b0bf2b018929ffd8799fd8799fd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0ffffffffd87b9f5f5840d8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457d57a22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffffffff"
"d8799fd8799fd87a9f581cd3a0d88f831105d2c1ab7ad0c31aa33bdeaa6c2503d2b0bf2b018929ffd8799fd8799fd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0ffffffffd8799fd8799fd8799f581cff310b072c281a4ef0e4166a00f9da571c4998cd57bb91764dfbdcf8ffd8799fd8799fd8799f581c0d33957c07acdddecc9882457da22f05e0d189f7fc95b1972e6d5105ffffffffd87980ffff"
);
});

Expand Down
13 changes: 3 additions & 10 deletions packages/core/src/DatumBuilders/contracts/contracts.v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,12 @@ export const AddressSchema = Data.Object({
),
});

export const DatumSchema = Data.Enum([
Data.Literal("NoDatum"),
Data.Object({ DatumHash: Data.Tuple([Data.Bytes()]) }),
Data.Object({ InlineDatum: Data.Tuple([Data.Any()]) }),
]);

export const DestinationSchema = Data.Object({
address: AddressSchema,
datum: DatumSchema,
datum: Data.Any(),
});
export type TDestinationDatum = Data.Static<typeof DestinationSchema>;
export const DestinationDatum =
DestinationSchema as unknown as TDestinationDatum;
export type TDestination = Data.Static<typeof DestinationSchema>;
export const Destination = DestinationSchema as unknown as TDestination;

export const IdentSchema = Data.Bytes();

Expand Down
13 changes: 2 additions & 11 deletions packages/core/src/TxBuilders/TxBuilder.Lucid.V1.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -902,15 +902,6 @@ export class TxBuilderLucidV1 extends TxBuilder {
throw new Error("Could not find a matching delegation!");
}

const dataHash = this.lucid.utils.datumToHash(
oldDelegation.datum as string
);

metadataDatums[`0x${dataHash}`] = SundaeUtils.splitMetadataString(
oldDelegation.datum as string,
"0x"
);

const config = {
newLockedAssets: returnedYFAssets,
depositPool,
Expand All @@ -919,8 +910,8 @@ export class TxBuilderLucidV1 extends TxBuilder {
DestinationAddress: {
address: lockContractAddress,
datum: {
type: EDatumType.HASH,
value: dataHash,
type: EDatumType.INLINE,
value: oldDelegation.datum as string,
},
},
AlternateAddress: yieldFarming.ownerAddress.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ describe("TxBuilderLucidV1", () => {
"0535c4f11b0ef42e85108b57eb4348a3a0a61686592cc74c55d1580717934706"
);
expect(withdrawOutput3?.datum()?.as_data_hash()?.to_hex()).toEqual(
"54dca498824cdec6accdc7039597985d3f40569071a8cc8a98941a3378d73bcc"
"595037c3b62bf0ea60911a23266a4752544177ccacf4416eafbd517975043414"
);

const transactionMetadata = builtTx.txComplete
Expand All @@ -736,7 +736,7 @@ describe("TxBuilderLucidV1", () => {
expect(
Buffer.from(transactionMetadata?.to_bytes() as Uint8Array).toString("hex")
).toEqual(
"a458204d4d325e63b5ca7158c4a6053526f5e4fc1d21c3582e9afd67c3855c29ea484988581fd8799fd8799f581c8bf66e915c450ad94866abb02802821b599e32f43536a4581f2470b21ea2ffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f521581f8b40691eea4514d0ff1a0007a120d8799fd8799fd8799f581cc279a3fb3b4e581f62bbc78e288783b58045d4ae82a18867d8352d02775affd8799fd8799fd879581f9f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0581fffffffffd87980ffd87b9f9f9f40401a086deb2cff9f581cfa3eff2047fdf9581f293c5feef4dc85ce58097ea1c6da4845a3515351834574494e44591a0436f54996ffffff43d87980ff582060098b625da105dba46b8c5abd55bf4cfa83ef8b4afb78a80f9e805eafbb097988581fd8799fd8799f581ca933477ea168013e2b5af4a9e029e36d26738eb6dfe382581fe1f3eab3e2ffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f521581f8b40691eea4514d0ff1a0007a120d8799fd8799fd8799f581cc279a3fb3b4e581f62bbc78e288783b58045d4ae82a18867d8352d02775affd8799fd8799fd879581f9f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0581fffffffffd87980ffd87b9f9f9f40401a07c18281ff9f581cd441227553a0f1581fa965fee7d60a0f724b368dd1bddbc208730fccebcf465242455252591a04944aec31ffffff43d87980ff5820ae02f4c4c993de87d8cfbf6b870326a97a0f4f674ff66ed895af257ff572c31182581fd8799fd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b4069481eea4514d0ff80ff5820b86891cd560f01904b117e785b266cf2c3d43b08274c86a1d10cd6463f5a7cbe89581fd8799fd8799f581ca933477ea168013e2b5af4a9e029e36d26738eb6dfe382581fe1f3eab3e2ffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f521581f8b40691eea4514d0ff1a0007a120d8799fd8799fd87a9f581c73275b9e267f581fd927bfc14cf653d904d1538ad8869260ab638bf73f5cffd8799fd8799fd879581f9f581c045d47cac5067ce697478c11051deb935a152e0773a5d7430a11baa8581fffffffffd87a9f5820ae02f4c4c993de87d8cfbf6b870326a97a0f4f674ff6581f6ed895af257ff572c311ffffd87b9f9f9f40401b0000001e4be5c9f7ff9f58581f1cd441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf46525642455252591b00000011e5baa103ffffff43d87980ff"
"a358204d4d325e63b5ca7158c4a6053526f5e4fc1d21c3582e9afd67c3855c29ea484988581fd8799fd8799f581c8bf66e915c450ad94866abb02802821b599e32f43536a4581f2470b21ea2ffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f521581f8b40691eea4514d0ff1a0007a120d8799fd8799fd8799f581cc279a3fb3b4e581f62bbc78e288783b58045d4ae82a18867d8352d02775affd8799fd8799fd879581f9f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0581fffffffffd87980ffd87b9f9f9f40401a086deb2cff9f581cfa3eff2047fdf9581f293c5feef4dc85ce58097ea1c6da4845a3515351834574494e44591a0436f54996ffffff43d87980ff582060098b625da105dba46b8c5abd55bf4cfa83ef8b4afb78a80f9e805eafbb097988581fd8799fd8799f581ca933477ea168013e2b5af4a9e029e36d26738eb6dfe382581fe1f3eab3e2ffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f521581f8b40691eea4514d0ff1a0007a120d8799fd8799fd8799f581cc279a3fb3b4e581f62bbc78e288783b58045d4ae82a18867d8352d02775affd8799fd8799fd879581f9f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0581fffffffffd87980ffd87b9f9f9f40401a07c18281ff9f581cd441227553a0f1581fa965fee7d60a0f724b368dd1bddbc208730fccebcf465242455252591a04944aec31ffffff43d87980ff58209320c8db6e0c105035f00d634831231fc13507322b6904307c9a9b4e9e564f6589581fd8799fd8799f581ca933477ea168013e2b5af4a9e029e36d26738eb6dfe382581fe1f3eab3e2ffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f521581f8b40691eea4514d0ff1a0007a120d8799fd8799fd87a9f581c73275b9e267f581fd927bfc14cf653d904d1538ad8869260ab638bf73f5cffd8799fd8799fd879581f9f581c045d47cac5067ce697478c11051deb935a152e0773a5d7430a11baa8581fffffffffd8799fd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f5581f218b40691eea4514d0ff80ffffd87b9f9f9f40401b0000001e4be5c9f7ff9f581f581cd441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf46575242455252591b00000011e5baa103ffffff43d87980ff"
);

const firstMigrationDatumBytes = builtTx.txComplete
Expand Down Expand Up @@ -772,7 +772,7 @@ describe("TxBuilderLucidV1", () => {
expect(
Buffer.from(thirdMigrationDatumBytes as Uint8Array).toString("hex")
).toEqual(
"d8799f4100d8799fd8799fd8799fd87a9f581c484969d936f484c45f143d911f81636fe925048e205048ee1fe412aaffd87a80ffd8799f5820b86891cd560f01904b117e785b266cf2c3d43b08274c86a1d10cd6463f5a7cbeffffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0ffff1a002625a0d87a9f1b000000174876e800ffff"
"d8799f4100d8799fd8799fd8799fd87a9f581c484969d936f484c45f143d911f81636fe925048e205048ee1fe412aaffd87a80ffd8799f58209320c8db6e0c105035f00d634831231fc13507322b6904307c9a9b4e9e564f65ffffd8799f581c121fd22e0b57ac206fefc763f8bfa0771919f5218b40691eea4514d0ffff1a002625a0d87a9f1b000000174876e800ffff"
);

expect(fees.cardanoTxFee?.amount).not.toBeUndefined();
Expand Down
19 changes: 0 additions & 19 deletions packages/yield-farming/src/@types/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ export type TDelegationOwner = Data.Static<typeof DelegationOwnerSchema>;
export const DelegationOwner =
DelegationOwnerSchema as unknown as TDelegationOwner;

// export const DelegationProgramMapSchema = Data.Array(
// Data.Tuple([Data.Bytes(), Data.Bytes({ minLength: 2 }), Data.Integer()])
// );
// export type TDelegationProgramMap = Data.Static<
// typeof DelegationProgramMapSchema
// >;
// export const DelegationProgramMap =
// DelegationProgramMapSchema as unknown as TDelegationProgramMap;

// export const DelegationProgramsSchema = Data.Object({
// value: Data.Enum([
// Data.Literal("None"),
// Data.Object({ List: DelegationProgramMapSchema }),
// ]),
// });
// export type TDelegationPrograms = Data.Static<typeof DelegationProgramsSchema>;
// export const DelegationPrograms =
// DelegationProgramsSchema as unknown as TDelegationPrograms;

export const DelegationProgramsSchema = Data.Array(
Data.Enum([
Data.Literal("None"),
Expand Down

0 comments on commit 54bd312

Please sign in to comment.