Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release the official version by Minswap Labs #58

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,53 @@ The smart contract has already been deployed on Testnet Preprod.

The detailed information on the deployment is located in [References](/deployed/preprod/references.json)

### Mainnet
The smart contract has already been deployed on Mainnet.

The detailed information on the deployment is located in [References](/deployed/mainnet/references.json)

Here is the deployed transaction:
- [Order](https://cardanoscan.io/transaction/cf4ecddde0d81f9ce8fcc881a85eb1f8ccdaf6807f03fea4cd02da896a621776)
- [Liquidity Pool](https://cardanoscan.io/transaction/2536194d2a976370a932174c10975493ab58fd7c16395d50e62b7c0e1949baea)
- [Factory](https://cardanoscan.io/transaction/59c7fa5c30cbab4e6d38f65e15d1adef71495321365588506ad089d237b602e0)
- [Authentication](https://cardanoscan.io/transaction/dbc1498500a6e79baa0f34d10de55cdb4289ca6c722bd70e1e1b78a858f136b9)
- [Liquidity Pool Batching](https://cardanoscan.io/transaction/d46bd227bd2cf93dedd22ae9b6d92d30140cf0d68b756f6608e38d680c61ad17)
- [Expired Order Cancellation](https://cardanoscan.io/transaction/ef3acc7dfc5a98bffe8f4d4400e65a9ade5a1316b2fcb7145c3b83dba38a66f5)

The smart contract parameters is located on [Params](/deployed/mainnet/params.json) file

Official Tokens and Smart contract address are maintained by Minswap Labs includes:
- Pool Validity Asset: f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c.4d5350
- Factory Validity Asset: f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c.4d5346
- Global Setting Validity Asset: f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c.4d534753
- LP Token Policy ID: f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c
- Pool Script Hash: ea07b733d932129c378af627436e7cbc2ef0bf96e0036bb51b3bde6b
- Order Script Hash: c3e28c36c3447315ba5a56f33da6a6ddc1770a876a8d9f0cb3a97c4c
- Factory Script Hash: 7bc5fbd41a95f561be84369631e0e35895efb0b73e0a7480bb9ed730
- Global Setting Script Hash: f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c
- Pool Creation Address (default address of a new liquidity pool): addr1z84q0denmyep98ph3tmzwsmw0j7zau9ljmsqx6a4rvaau66j2c79gy9l76sdg0xwhd7r0c0kna0tycz4y5s6mlenh8pq777e2a
- Liquidity Pool Batching stake address: stake17y02a946720zw6pw50upt2arvxsvvpvaghjtl054h0f0gjsfyjz59
- Expired Order Cancellation stake address: stake178ytpnrpxax5p8leepgjx9cq8ecedgly6jz4xwvvv4kvzfq9s6295

Example transactions:
- [DEX Initialization](https://cardanoscan.io/transaction/22a2ae40124855a98b262e32b69218c51c6a159cd4fa99f1c34a798d3a0ff8a9)
- [Liquidity Pool Creation](https://cardanoscan.io/transaction/3167ca40518b1b77b331aeda378e36997a566ec7b557d70eb026aa952e2ecf6d)
- [Batching](https://cardanoscan.io/transaction/a544364aacd0f8b61aa8abf9f024e06e57a8858669eead2d3aaab0b9878e1bc3)
- [Swap Exact In](https://cardanoscan.io/transaction/a0fc29c9191762ab3485bc431616d306de0ff414d8f785ffa59d40a8fc7dc0df)
- [Limit](https://cardanoscan.io/transaction/bd824cdfb80f5fc722dedc494bf94eb06794ca724bfc27c4dd5fcbbdd91b1d66)
- [Stop](https://cardanoscan.io/transaction/18f9f12dec65d8e84e06f8c202710d4cf366081a4ce94b05855cca2b6834459e
)
- [OCO](https://cardanoscan.io/transaction/c76594de9d089698055e6034547b71da46c5db43567c37472f827fe77d99fc34
)
- [Partial Swap](https://cardanoscan.io/transaction/1615cd9caddf206ab22dee08d364f2950448cf6b91352142eed5b37308e81df1)
- [Zap In](https://cardanoscan.io/transaction/4ec9236ea1ff0e4767b30f9f4d1e8bc0d2ce7262513ab3f9d944cd04fe3fd8b3)
- [Deposit](https://cardanoscan.io/transaction/8354d700e233878cf460c7821b8b49e8158c96aaa462f8e6d43aa66994a93837)
- [Zap Out](https://cardanoscan.io/transaction/46046d1f4a68227802d6057b1815ac93ec7ee572ee2957aef1527170fcbb4ef1)
- [Withdraw](https://cardanoscan.io/transaction/5313373a182fb26bc7e097f1c32de7cdb89d3c9da6e00d625b0f3684477615cd)
- [Order Cancellation](https://cardanoscan.io/transaction/ca11ebacbbff1b93b72abb71083ac41c95c2d237af5091dc95519f76e2799e27)
- [Expired Order Cancellation](https://cardanoscan.io/transaction/ce350ae5822281a3bbccdab61719ca97ecf3955b9b496e27b6e18aba4dc4bf1a)


## Audit Report

The contract audit has been conducted by Certik and Anastasia Labs
Expand All @@ -37,4 +84,4 @@ The Audit report is available under [Audit Report](/audit-report) folder
## References

1. [Specification](/amm-v2-docs/amm-v2-specs.md)
2. [Formula](/amm-v2-docs/formula.md)
2. [Formula](/amm-v2-docs/formula.md)
10 changes: 10 additions & 0 deletions deployed/mainnet/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"seedTxIn": "1510c33ecb621e61f3c0568ac10ebd08fe4fce35f130db859f28e4db4c7d7a1f#0",
"factoryNFTName": "MSF",
"poolNFTName": "MSP",
"globalSettingNFTName": "MSGS",
"poolStakeCredential": {
"type": "Key",
"hash": "52563c5410bff6a0d43ccebb7c37e1f69f5eb260552521adff33b9c2"
}
}
14 changes: 14 additions & 0 deletions deployed/mainnet/references.json

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions deployed/mainnet/script.json

Large diffs are not rendered by default.

39 changes: 20 additions & 19 deletions deployed/preprod/script.json

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions src/batcher-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import { sha3 } from "./hash";
import { EmulatorProvider } from "./provider";
import { getContractScripts } from "./script";
import { ADA, Asset } from "./types/asset";
import { GlobalSetting, PoolAuthorizationMethodType } from "./types/global-setting";
import {
GlobalSetting,
PoolAuthorizationMethodType,
} from "./types/global-setting";
import { NetworkId } from "./types/network";
import {
OrderAuthorizationMethodType,
OrderAmountType,
OrderAuthorizationMethodType,
OrderDatum,
OrderDirection,
OrderExtraDatumType,
Expand Down Expand Up @@ -242,32 +245,42 @@ function getGlobalSetting(lucid: Lucid): {
batchers: [
{
type: PoolAuthorizationMethodType.SIGNATURE,
hash: lucid.utils.paymentCredentialOf(pubkeyBatcher.batcherAddr).hash
hash: lucid.utils.paymentCredentialOf(pubkeyBatcher.batcherAddr).hash,
},
{
type: PoolAuthorizationMethodType.SPEND_SCRIPT,
hash: lucid.utils.paymentCredentialOf(scriptBatcher.batcherAddr).hash
}
hash: lucid.utils.paymentCredentialOf(scriptBatcher.batcherAddr).hash,
},
],
admin: {
type: PoolAuthorizationMethodType.SIGNATURE,
hash: lucid.utils.paymentCredentialOf("addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc").hash
hash: lucid.utils.paymentCredentialOf(
"addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc"
).hash,
},
feeSharingTaker: {
type: PoolAuthorizationMethodType.SIGNATURE,
hash: lucid.utils.paymentCredentialOf("addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc").hash
hash: lucid.utils.paymentCredentialOf(
"addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc"
).hash,
},
poolDynamicFeeUpdater: {
type: PoolAuthorizationMethodType.SIGNATURE,
hash: lucid.utils.paymentCredentialOf("addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc").hash
hash: lucid.utils.paymentCredentialOf(
"addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc"
).hash,
},
poolFeeUpdater: {
type: PoolAuthorizationMethodType.SIGNATURE,
hash: lucid.utils.paymentCredentialOf("addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc").hash
hash: lucid.utils.paymentCredentialOf(
"addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc"
).hash,
},
poolStakeKeyUpdater: {
type: PoolAuthorizationMethodType.SIGNATURE,
hash: lucid.utils.paymentCredentialOf("addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc").hash
hash: lucid.utils.paymentCredentialOf(
"addr_test1vqe2eyupqj8e0jr8uumakm2zuhh2ucrcevy7hw8vztjaragvljjnc"
).hash,
},
};
return {
Expand Down
14 changes: 11 additions & 3 deletions src/build-plutus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import { getContractScripts } from "./script";
import { NetworkId } from "./types/network";

async function main() {
const lucid = await Lucid.new(new EmulatorProvider(), "Preprod");
const lucidTestnet = await Lucid.new(new EmulatorProvider(), "Preprod");

const scripts = getContractScripts(lucid, NetworkId.TESTNET);
const testnetScripts = getContractScripts(lucidTestnet, NetworkId.TESTNET);
fs.writeFileSync(
`deployed/preprod/script.json`,
JSON.stringify(scripts, null, 4)
JSON.stringify(testnetScripts, null, 4)
);

const lucidMainnet = await Lucid.new(new EmulatorProvider(), "Mainnet");

const mainnetScripts = getContractScripts(lucidMainnet, NetworkId.MAINNET);
fs.writeFileSync(
`deployed/mainnet/script.json`,
JSON.stringify(mainnetScripts, null, 4)
);
}

Expand Down
91 changes: 48 additions & 43 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ type ContractParameters = {
poolDefaultStakeKey: Credential;
};

export function getContractParameters(networkId: NetworkId): ContractParameters {
export function getContractParameters(
networkId: NetworkId
): ContractParameters {
const cases: Record<string, string> = {
[NetworkId.TESTNET]: "deployed/preprod/params.json",
[NetworkId.MAINNET]: "deployed/mainnet/params.json", // Not decided yet
[NetworkId.MAINNET]: "deployed/mainnet/params.json",
};
const path = cases[networkId];
let params = JSON.parse(fs.readFileSync(path, 'utf-8'));
let seedTxInParts = params.seedTxIn.split("#");
const params = JSON.parse(fs.readFileSync(path, "utf-8"));
const seedTxInParts = params.seedTxIn.split("#");
return {
seedTxIn: {
txId: seedTxInParts[0],
Expand All @@ -50,7 +52,7 @@ export function getContractParameters(networkId: NetworkId): ContractParameters
globalSettingNFTName: params.globalSettingNFTName,
poolDefaultStakeKey: params.poolStakeCredential,
};
};
}

function readValidator(): {
order: SpendingValidator;
Expand Down Expand Up @@ -120,35 +122,37 @@ function readValidator(): {
}

type ContractScript = {
authenPolicyId: string;
authenAddress: string;
poolAddress: string;
orderAddress: string;
factoryAddress: string;
expiredOrderCancellationAddress: string;
// Authentication asset
factoryAsset: Asset;
poolAuthenAsset: Asset;
globalSettingAsset: Asset;

// LP PolicyID
lpPolicyId: string;

// Smart contract address
globalSettingEnterpriseAddress: string;
orderEnterpriseAddress: string;
poolEnterpriseAddress: string;
poolCreationAddress: string;
factoryEnterpriseAddress: string;
expiredOrderCancelAddress: string;
poolBatchingAddress: string;
poolBatchingCredential: Credential;
poolAuthAsset: Asset;
factoryAuthAsset: Asset;
globalSettingAsset: Asset;

// Smart contract script
authenScript: Script;
poolScript: Script;
orderScript: Script;
authenScript: Script;
factoryScript: Script;
expiredOrderCancelScript: Script;
poolBatchingScript: Script;
};

let contractScript: ContractScript | undefined = undefined;

export function getContractScripts(
lucid: Lucid,
networkId: NetworkId
): ContractScript {
if (contractScript) {
return contractScript;
}
const validators = readValidator();
const {
seedTxIn,
Expand Down Expand Up @@ -214,47 +218,48 @@ export function getContractScripts(
]),
};

const authenAddress = lucid.utils.validatorToAddress(authenMintingScript);
const poolAddress = lucid.utils.validatorToAddress(poolScript);
const orderAddress = lucid.utils.validatorToAddress(orderScript);
const factoryAddress = lucid.utils.validatorToAddress(factoryScript);
const globalSettingAddress =
lucid.utils.validatorToAddress(authenMintingScript);
const poolEnterpriseAddress = lucid.utils.validatorToAddress(poolScript);
const orderEnterpriseAddress = lucid.utils.validatorToAddress(orderScript);
const factoryEnterpriseAddress =
lucid.utils.validatorToAddress(factoryScript);
const expiredOrderCancellationAddress = lucid.utils.validatorToRewardAddress(
expiredOrderCancellationScript
);
const poolBatchingAddress =
lucid.utils.validatorToRewardAddress(poolBatchingScript);

contractScript = {
authenPolicyId,
authenAddress,
orderAddress,
poolAddress,
factoryAddress,
expiredOrderCancellationAddress,
poolBatchingAddress,
poolBatchingCredential: {
type: "Script",
hash: poolBatchingHash,
},
poolAuthAsset: {
return {
factoryAsset: {
policyId: authenPolicyId,
tokenName: fromText(poolNFTName),
tokenName: fromText(factoryNFTName),
},
factoryAuthAsset: {
poolAuthenAsset: {
policyId: authenPolicyId,
tokenName: fromText(factoryNFTName),
tokenName: fromText(poolNFTName),
},
globalSettingAsset: {
policyId: authenPolicyId,
tokenName: fromText(globalSettingNFTName),
},
lpPolicyId: authenPolicyId,
globalSettingEnterpriseAddress: globalSettingAddress,
orderEnterpriseAddress: orderEnterpriseAddress,
poolEnterpriseAddress: poolEnterpriseAddress,
poolCreationAddress: poolCreationAddress,
factoryEnterpriseAddress: factoryEnterpriseAddress,
expiredOrderCancelAddress: expiredOrderCancellationAddress,
poolBatchingAddress: poolBatchingAddress,
poolBatchingCredential: {
type: "Script",
hash: poolBatchingHash,
},
authenScript: authenMintingScript,
poolScript: poolScript,
orderScript: orderScript,
authenScript: authenMintingScript,
factoryScript: factoryScript,
expiredOrderCancelScript: expiredOrderCancellationScript,
poolBatchingScript: poolBatchingScript,
};

return contractScript;
}
1 change: 0 additions & 1 deletion src/types/global-setting.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Constr, Data } from "lucid-cardano";

import { AddressPlutusData } from "./address";

export enum PoolAuthorizationMethodType {
SIGNATURE = 0,
Expand Down
Loading