Skip to content

Commit

Permalink
wip: poc
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkoepke committed Jun 19, 2024
1 parent 967ab78 commit a946b35
Show file tree
Hide file tree
Showing 25 changed files with 1,082 additions and 11,959 deletions.
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

Binary file added bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"useNx": true,
"useWorkspaces": true,
"version": "independent",
"npmClient": "yarn",
"npmClient": "bun",
"ignoreChanges": [
"**/__tests__/**",
"**/__fixtures__/**",
"**/*.test.js",
"**/*.md"
],
"ignore": "demo",
"ignore": "demo|core",
"command": {
"version": {
"message": "chore(release): publish %s",
Expand Down
27 changes: 9 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"type": "module",
"private": true,
"workspaces": [
"packages/*"
"./packages/builder",
"./packages/core"
],
"scripts": {
"postinstall": "lerna bootstrap",
"test": "yarn node --max-old-space-size=6000 --no-warnings --experimental-vm-modules $(yarn bin jest)",
"lint": "eslint ./packages --ext js,jsx,ts,tsx",
"lint:fix": "yarn lint --fix",
"prepare": "husky install",
"prepare": "husky",
"typecheck": "lerna run typecheck",
"build": "lerna run build",
"version:ci": "lerna version -y --ignore-scripts",
Expand All @@ -31,32 +31,23 @@
"@semantic-release/git": "^10.0.1",
"@sundaeswap/asset": "^0.7.1",
"@sundaeswap/docgen": "^0.1.2",
"@sundaeswap/prettier-config": "^2.0.3",
"@types/bun": "^1.1.4",
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.11",
"@typescript-eslint/eslint-plugin": "^5",
"@typescript-eslint/parser": "^5",
"concurrently": "^8.2.1",
"eslint": "^8.31.0",
"eslint-config-next": "^12",
"eslint-config-prettier": "^8",
"eslint-plugin-import": "^2",
"eslint-plugin-jest": "^26",
"eslint-plugin-jsx-a11y": "^6",
"eslint-plugin-prettier": "^4",
"eslint-plugin-react": "^7",
"eslint-plugin-react-hooks": "^4",
"glob": "^8.0.3",
"husky": "^8.0.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-dom": "^4.0.0",
"jest-fetch-mock": "^3.0.3",
"lerna": "^5.6.2",
"lerna": "^8.1.3",
"lint-staged": "^15.1.0",
"log-update": "^6.0.0",
"lucid-cardano": "^0.10.7",
"prettier": "^2",
"prettier": "^3.3.2",
"ts-jest": "^29.0.4",
"ts-node": "^10.9.1"
},
"dependencies": {}
}
}
20 changes: 20 additions & 0 deletions packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@sundaeswap/builder",
"version": "1.0.0",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"type": "module",
"peerDependencies": {
"lucid-cardano": "0.10.7",
"@sundaeswap/core": "workspace:*"
},
"peerDependenciesMeta": {
"lucid-cardano": {
"optional": true
}
},
"dependencies": {
"@sundaeswap/asset": "^0.7.1"
}
}
174 changes: 174 additions & 0 deletions packages/builder/src/@types/datumbuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import type { AssetAmount, IAssetAmountMetadata } from "@sundaeswap/asset";

/**
* The unique identifier of a pool, defined as a string.
*/
export type TIdent = string;

/**
* The structure for a UTXO.
*/
export type TUTXO = {
hash: string;
index: number;
};

/**
* A hex-encoded public key hash of an address.
*/
export type TPubKeyHash = string;

/**
* The boolean type of a pool's coin, where 0 = CoinA and 1 = CoinB.
*/
export enum EPoolCoin {
A = 0,
B = 1,
}

/**
* The Datum type to be passed along with an address.
*/
export enum EDatumType {
HASH = "HASH",
INLINE = "INLINE",
NONE = "NONE",
}

/**
* The DatumNone type is used to describe a null datum.
*/
export type TDatumNone = {
type: EDatumType.NONE;
};

/**
* The DatumHash type is use to describe a datum hash.
*/
export type TDatumHash = {
type: EDatumType.HASH;
value: string;
};

/**
* The DatumInline type is used to describe an inline datum.
*/
export type TDatumInline = {
type: EDatumType.INLINE;
value: string;
};

/**
* The DatumResult for a DatumBuilder method.
*/
export type TDatumResult<Schema = unknown> = {
hash: string;
inline: string;
schema: Schema;
};

/**
* A union to define all possible datum types.
*/
export type TDatum = TDatumNone | TDatumHash | TDatumInline;

/**
* Defines the destination address of a swap along with an optional datum hash to attach.
*/
export type TDestinationAddress = {
address: string;
datum: TDatum;
};

/**
* The optional alternate address that can cancel the Escrow order. This is
* needed because a {@link TDestinationAddress} can be a Script Address. This
* is useful to chain swaps with other protocols if desired, while still allowing
* a consistently authorized alternate to cancel the Escrow.
*/
export type TCancelerAddress = string;

/**
* An Escrow address defines the destination address and an optional PubKeyHash
*/
export type TOrderAddresses = {
DestinationAddress: TDestinationAddress;
AlternateAddress?: TCancelerAddress;
};

/**
* The swap direction of a coin pair, and a minimum receivable amount
* which acts as the limit price of a swap.
*/
export type TSwap = {
SuppliedCoin: EPoolCoin;
MinimumReceivable?: AssetAmount;
};

/**
* A withdraw defines the amount of LP tokens a holder wishes to burn in exchange
* for their provided assets.
*/
export type TWithdraw = AssetAmount;

/**
* A single asset deposit where 50% of the provided Coin is swapped at the provided minimum
* receivable amount to satisfy a pool's CoinA/CoinB requirements.
*/
export type TDepositSingle = {
ZapDirection: EPoolCoin;
CoinAmount: AssetAmount;
};

/**
* The CoinA and CoinB asset pair of a pool at the desired ratio. If the ratio
* shifts after the order is placed but before it is scooped, the LP tokens along with
* the remaining asset gets sent to the {@link TDestinationAddress}
*/
export type TDepositMixed = {
CoinAAmount: AssetAmount;
CoinBAmount: AssetAmount;
};

/**
* Base arguments for every datum constructor.
*/
export interface IArguments {
/** The unique pool identifier. */
ident: string;
/** The addresses that are allowed to cancel the Order. */
orderAddresses: TOrderAddresses;
/** The fee paid to scoopers. */
scooperFee: bigint;
}

/**
* Arguments for a swap.
*/
export interface ISwapArguments extends IArguments {
swap: TSwap;
/** The asset supplied (this is required to accurately determine the swap direction). */
fundedAsset: AssetAmount<IAssetAmountMetadata>;
}

/**
* Arguments for a withdraw.
*/
export interface IWithdrawArguments extends IArguments {
/** The LP tokens to send to the pool. */
suppliedLPAsset: AssetAmount<IAssetAmountMetadata>;
}

/**
* Arguments for depositing a pair of assets into a pool.
*/
export interface IDepositArguments extends IArguments {
deposit: TDepositMixed;
}

/**
* Arguments for zapping an asset into a pool.
*/
export interface IZapArguments extends IArguments {
zap: TDepositSingle;
}
8 changes: 8 additions & 0 deletions packages/builder/src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* The contract version to be used when building transactions
* of any time that interact with SundaeSwap contracts.
*/
export enum EContractVersion {
V1 = "V1",
V3 = "V3",
}
Loading

0 comments on commit a946b35

Please sign in to comment.