Skip to content

Commit f7633eb

Browse files
committed
build scripts, update benchmark, add run script
1 parent c79f420 commit f7633eb

File tree

3 files changed

+75
-29
lines changed

3 files changed

+75
-29
lines changed

lucid/main.ts

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function settingsDatum(poolStakeHash: string, userPkh: string): string {
6666
],
6767
authorizedStakingKeys: [
6868
{
69-
VKeyCredential: { bytes: poolStakeHash },
69+
SCredential: { bytes: poolStakeHash },
7070
}
7171
],
7272
baseFee: 1000000n,
@@ -120,13 +120,15 @@ async function listOrder(lucid: Lucid, scripts: Scripts, userPkh: string, assets
120120
},
121121
scooperFee: scooperFee,
122122
destination: {
123-
address: {
124-
paymentCredential: {
125-
VKeyCredential: { bytes: userPkh },
123+
Fixed: {
124+
address: {
125+
paymentCredential: {
126+
VKeyCredential: { bytes: userPkh },
127+
},
128+
stakeCredential: null,
126129
},
127-
stakeCredential: null,
130+
datum: "NoDatum",
128131
},
129-
datum: "NoDatum",
130132
},
131133
order: {
132134
Swap: {
@@ -508,7 +510,9 @@ async function mintPool(scripts: Scripts, lucid: Lucid, userAddress: Address, se
508510
identifier: toHex(poolId),
509511
assets: assets,
510512
circulatingLp: liq,
511-
feesPer10Thousand: fees,
513+
bidFeesPer10Thousand: fees,
514+
askFeesPer10Thousand: fees,
515+
feeManager: null,
512516
marketOpen: marketOpen || 0n,
513517
feeFinalized: marketOpen || 0n,
514518
protocolFees: 2_000_000n,
@@ -536,6 +540,17 @@ async function mintPool(scripts: Scripts, lucid: Lucid, userAddress: Address, se
536540
const poolMintRedeemerBytes = Data.to(poolMintRedeemer, types.PoolMintRedeemer);
537541
const poolDatumBytes = Data.to(newPoolDatum, types.PoolDatum);
538542

543+
const poolAddress = (new Utils(lucid)).credentialToAddress(
544+
{
545+
type: "Script",
546+
hash: scripts.poolScriptHash,
547+
},
548+
{
549+
type: "Script",
550+
hash: scripts.poolStakeHash,
551+
}
552+
);
553+
539554
console.log("value: ");
540555
console.log(poolValue);
541556
console.log("newPoolDatum: ");
@@ -544,6 +559,8 @@ async function mintPool(scripts: Scripts, lucid: Lucid, userAddress: Address, se
544559
console.log(poolMintRedeemerBytes);
545560
console.log("settings datum: ");
546561
console.log(settings.datum);
562+
console.log("pool address: ");
563+
console.log(poolAddress);
547564
console.log("-------");
548565
console.log("seed: ", seed);
549566
const tx = lucid.newTx()
@@ -554,15 +571,19 @@ async function mintPool(scripts: Scripts, lucid: Lucid, userAddress: Address, se
554571
}, poolMintRedeemerBytes)
555572
.readFrom([...references, settings])
556573
.collectFrom([seed])
557-
.payToContract(scripts.poolAddress, { inline: poolDatumBytes }, poolValue)
574+
.payToContract(poolAddress, { inline: poolDatumBytes }, poolValue)
558575
.payToAddress(userAddress, {
559576
"lovelace": 2_000_000n,
560577
[toUnit(scripts.poolPolicyId, poolLqNameHex)]: liq,
561578
})
562-
.payToAddress(userAddress, {
563-
"lovelace": 2_000_000n,
564-
[toUnit(scripts.poolPolicyId, poolRefNameHex)]: 1n,
565-
});
579+
.payToAddressWithData(
580+
userAddress,
581+
{ inline: "d87980" },
582+
{
583+
"lovelace": 2_000_000n,
584+
[toUnit(scripts.poolPolicyId, poolRefNameHex)]: 1n,
585+
}
586+
);
566587

567588
const str = await tx.toString();
568589
console.log("building tx: " + str);
@@ -644,8 +665,8 @@ async function testMintPool(lucid: Lucid, emulator: Emulator, scripts: Scripts,
644665
const settings = settingsUtxos[0];
645666

646667
const minted = await mintPool(scripts, lucid, userAddress, settings, [refUtxo], assets, seed, 1_000_000_000n, 1_000_000_000n, [5n, 5n]);
647-
await emulator.awaitTx(minted.mintedHash);
648-
console.log("Minted a pool, hash: " + minted.mintedHash);
668+
await emulator.awaitTx(minted.poolMintedHash);
669+
console.log("Minted a pool, hash: " + minted.poolMintedHash);
649670
return minted;
650671
}
651672

@@ -739,16 +760,16 @@ async function executeOrder(poolABL: ABL, poolDatum: types.PoolDatum, order: UTx
739760
let res: ABL = { a: 0n, b: 0n, liq: 0n };
740761
if ("Swap" in orderDatum.order) {
741762
if (orderDatum.order.Swap.offer[0] + orderDatum.order.Swap.offer[1] == poolCoinA) {
742-
[res, poolABL] = doSwap(Coin.CoinA, orderDatum.order.Swap.offer[2], poolDatum.feesPer10Thousand, poolABL);
763+
[res, poolABL] = doSwap(Coin.CoinA, orderDatum.order.Swap.offer[2], poolDatum.bidFeesPer10Thousand, poolABL);
743764
console.log("after swapping for coinA, poolABL will be: ");
744765
console.log(poolABL);
745766
} else if (orderDatum.order.Swap.offer[0] + orderDatum.order.Swap.offer[1] == poolCoinB) {
746-
[res, poolABL] = doSwap(Coin.CoinB, orderDatum.order.Swap.offer[2], poolDatum.feesPer10Thousand, poolABL);
767+
[res, poolABL] = doSwap(Coin.CoinB, orderDatum.order.Swap.offer[2], poolDatum.askFeesPer10Thousand, poolABL);
747768
} else {
748769
throw new Error("Order does not appear to match the pool");
749770
}
750771
}
751-
const dest = await fromOrderDatumAddress(orderDatum.destination.address);
772+
const dest = await fromOrderDatumAddress(orderDatum.destination.Fixed.address);
752773
return [poolABL, {
753774
abl: res,
754775
destination: dest,
@@ -828,9 +849,9 @@ async function scoopPool(scripts: Scripts, lucid: Lucid, userAddress: Address, s
828849
toSpend.push(...orderUtxos);
829850
toSpend.sort((a, b) => a.txHash == b.txHash ? a.outputIndex - b.outputIndex : (a.txHash < b.txHash ? -1 : 1));
830851
for (let e of toSpend) {
831-
if (e.address == scripts.poolAddress) {
852+
if (getAddressDetails(e.address).paymentCredential.hash == scripts.poolScriptHash) {
832853
tx.collectFrom([e], redeemerData);
833-
} else if (e.address == scripts.orderAddress) {
854+
} else if (getAddressDetails(e.address).paymentCredential.hash == scripts.orderScriptHash) {
834855
tx.collectFrom([e], Data.to(orderScoopRedeemer, types.OrderRedeemer));
835856
} else {
836857
tx.collectFrom([e]);
@@ -856,7 +877,7 @@ async function scoopPool(scripts: Scripts, lucid: Lucid, userAddress: Address, s
856877
.addSigner(userAddress)
857878
.withdraw(scripts.steakAddress, 0n, "00")
858879

859-
.payToContract(scripts.poolAddress, { inline: newPoolDatum }, {
880+
.payToContract(targetPool.address, { inline: newPoolDatum }, {
860881
"lovelace":
861882
newPoolABL.a +
862883
poolDatum.protocolFees,
@@ -920,7 +941,18 @@ async function testScoopPool(lucid: Lucid, emulator: Emulator, scripts: Scripts,
920941
}
921942
const settings = settingsUtxos[0];
922943

923-
let knownPools = await emulator.getUtxos(scripts.poolAddress);
944+
const poolAddress = (new Utils(lucid)).credentialToAddress(
945+
{
946+
type: "Script",
947+
hash: scripts.poolScriptHash,
948+
},
949+
{
950+
type: "Script",
951+
hash: scripts.poolStakeHash,
952+
}
953+
);
954+
955+
let knownPools = await emulator.getUtxos(poolAddress);
924956

925957
let targetPool = null;
926958
for (let knownPool of knownPools) {
@@ -1060,8 +1092,8 @@ const accounts: any[] = [
10601092
];
10611093
let emulator = new Emulator(accounts, {
10621094
...PROTOCOL_PARAMETERS_DEFAULT,
1063-
//maxTxSize: 999999999999,
1064-
//maxTxExMem: 999999999999999n,
1095+
maxTxSize: 999999999999,
1096+
maxTxExMem: 999999999999999n,
10651097
});
10661098
let lucid = await Lucid.new(emulator);
10671099

@@ -1128,7 +1160,7 @@ emulator.ledger["000000000000000000000000000000000000000000000000000000000000000
11281160

11291161
const listOrdersChange = emulator.ledger["00000000000000000000000000000000000000000000000000000000000000001"].utxo;
11301162

1131-
const { listedHash, utxos: orders } =
1163+
const { listedHash, utxos: orders } =
11321164
await testListOrder(lucid, emulator, scripts, "lovelace", rberry, listOrdersChange, poolId, 40n);
11331165

11341166
const scoopPoolChange = await findChange(emulator, userAddress);

lucid/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Make sure to build the aiken scripts first
2+
deno run \
3+
--allow-read \
4+
main.ts \
5+
--scriptsFile ../plutus.json

lucid/types.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,17 @@ export const DatumSchema = Data.Enum([
110110
//Data.Object({ InlineDatum: Data.Any() }),
111111
]);
112112

113-
export const DestinationSchema = Data.Object({
114-
address: AddressSchema,
115-
datum: DatumSchema,
116-
});
113+
export const DestinationSchema = Data.Enum([
114+
Data.Object({
115+
Fixed: Data.Object({
116+
address: AddressSchema,
117+
datum: DatumSchema,
118+
}),
119+
}),
120+
Data.Object({
121+
Self: Data.Tuple([]),
122+
}),
123+
]);
117124

118125
export const ExtensionSchema = Data.Enum([
119126
Data.Literal("NoExtension"),
@@ -139,7 +146,9 @@ export const PoolDatumSchema = Data.Object({
139146
identifier: IdentSchema,
140147
assets: Data.Tuple([AssetClassSchema, AssetClassSchema]),
141148
circulatingLp: Data.Integer(),
142-
feesPer10Thousand: Data.Tuple([Data.Integer(), Data.Integer()]),
149+
bidFeesPer10Thousand: Data.Tuple([Data.Integer(), Data.Integer()]),
150+
askFeesPer10Thousand: Data.Tuple([Data.Integer(), Data.Integer()]),
151+
feeManager: Data.Nullable(MultiSigScriptSchema),
143152
marketOpen: Data.Integer(),
144153
feeFinalized: Data.Integer(),
145154
protocolFees: Data.Integer(),

0 commit comments

Comments
 (0)