Skip to content

Commit

Permalink
Merge pull request #56 from SundaeSwap-finance/feat/blaze
Browse files Browse the repository at this point in the history
Add Blaze Support
  • Loading branch information
cjkoepke authored Aug 26, 2024
2 parents f79bdb0 + 857f864 commit d689229
Show file tree
Hide file tree
Showing 199 changed files with 16,546 additions and 1,985 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
"no-delete-var": "warn",
"no-debugger": "error",
"no-dupe-args": "warn",
"no-dupe-class-members": "warn",
"no-dupe-class-members": "off",
"no-dupe-keys": "warn",
"no-duplicate-case": "warn",
"no-empty-character-class": "warn",
Expand Down
165 changes: 165 additions & 0 deletions docs/typescript/core/classes/Blaze.BlazeHelper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Class: BlazeHelper

[Blaze](../modules/Blaze.md).BlazeHelper

A helper class that provides utility functions for validating and processing
Cardano addresses. These functions include:
- Parsing address hashes from a Bech32 or hex encoded address
- Validating an address as being a valid Cardano address and that it is on the correct network
- Checking if an address is a script address
- Validating that an address matches the given network
- Throwing an error if the address is on the wrong network
- Throwing an error if an invalid address is supplied

**`Example`**

```typescript
const hashes = BlazeHelper.getAddressHashes("addr_test...")
BlazeHelper.validateAddressAndDatumAreValid({ address: "addr_test...", network: "mainnet" });
const isScript = BlazeHelper.isScriptAddress("addr_test...");
```

## Methods

### getAddressHashes

**getAddressHashes**(`address`): `Object`

Helper function to parse addresses hashes from a Bech32 encoded address.

#### Parameters

| Name | Type |
| :------ | :------ |
| `address` | `string` |

#### Returns

`Object`

| Name | Type |
| :------ | :------ |
| `paymentCredentials` | `Hash28ByteBase16` |
| `stakeCredentials?` | `string` |

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:28](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L28)

___

### isScriptAddress

**isScriptAddress**(`address`): `boolean`

Helper function to check if an address is a script address.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `address` | `string` | The Bech32 encoded address. |

#### Returns

`boolean`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:137](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L137)

___

### maybeThrowNetworkError

**maybeThrowNetworkError**(`addressNetwork`, `address`, `network`): `void`

Throws a useful error if the address, network, and instance network are on the wrong network.

#### Parameters

| Name | Type |
| :------ | :------ |
| `addressNetwork` | `number` |
| `address` | `string` |
| `network` | [`TSupportedNetworks`](../modules/Core.md#tsupportednetworks) |

#### Returns

`void`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:183](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L183)

___

### throwInvalidOrderAddressesError

**throwInvalidOrderAddressesError**(`address`, `errorMessage`): `never`

Throws an error describing the address and contextual information.

#### Parameters

| Name | Type |
| :------ | :------ |
| `address` | `string` |
| `errorMessage` | `string` |

#### Returns

`never`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:210](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L210)

___

### validateAddressAndDatumAreValid

**validateAddressAndDatumAreValid**(`«destructured»`): `void`

Validates that an address and optional datum are valid,
and that the address is on the correct network.

#### Parameters

| Name | Type |
| :------ | :------ |
| `«destructured»` | `Object` |
| › `address` | `string` |
| › `datum` | [`TDatum`](../modules/Core.md#tdatum) |
| › `network` | [`TSupportedNetworks`](../modules/Core.md#tsupportednetworks) |

#### Returns

`void`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:80](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L80)

___

### validateAddressNetwork

**validateAddressNetwork**(`address`, `network`): `void`

Validates that an address matches the provided network.

#### Parameters

| Name | Type |
| :------ | :------ |
| `address` | `string` |
| `network` | [`TSupportedNetworks`](../modules/Core.md#tsupportednetworks) |

#### Returns

`void`

#### Defined in

[packages/core/src/Utilities/BlazeHelper.class.ts:151](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/Utilities/BlazeHelper.class.ts#L151)
123 changes: 123 additions & 0 deletions docs/typescript/core/classes/Blaze.DatumBuilderBlazeV1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Class: DatumBuilderBlazeV1

[Blaze](../modules/Blaze.md).DatumBuilderBlazeV1

The Blaze implementation for building valid Datums for
V1 contracts on the SundaeSwap protocol.

## Implements

- [`DatumBuilder`](Core.DatumBuilder.md)

## Properties

### network

**network**: [`TSupportedNetworks`](../modules/Core.md#tsupportednetworks)

The current network id.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:41](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L41)

___

### INVALID\_POOL\_IDENT

`Static` **INVALID\_POOL\_IDENT**: `string` = `"You supplied a pool ident of an invalid length! The will prevent the scooper from processing this order."`

The error to throw when the pool ident does not match V1 constraints.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:43](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L43)

## Methods

### buildDepositDatum

**buildDepositDatum**(`params`): [`TDatumResult`](../modules/Core.md#tdatumresult)\<\{ `DepositPair`: ``"VOID"`` \| \{ `Parent`: \{ `Child`: ``"VOID"`` \| \{ `Value`: \{ `pair`: \{ `a`: `bigint` ; `b`: `bigint` } } } } } ; `ident`: `string` ; `orderAddresses`: \{ `alternate`: ``null`` \| `string` ; `destination`: \{ `credentials`: \{ `paymentKey`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } ; `stakingKey`: ``null`` \| \{ `value`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } } } ; `datum`: ``null`` \| `string` } } ; `scooperFee`: `bigint` }\>

Creates a deposit datum object from the given deposit arguments. The function initializes
a new datum with specific properties such as the pool ident, order addresses, scooper fee,
and deposit pair schema. It then converts this datum into an inline format and calculates
its hash using [Blaze.BlazeHelper](Blaze.BlazeHelper.md). The function returns an object containing the hash of the inline
datum, the inline datum itself, and the original datum schema.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `params` | [`IDepositArguments`](../interfaces/Core.IDepositArguments.md) | The deposit arguments required to construct the deposit datum. |

#### Returns

[`TDatumResult`](../modules/Core.md#tdatumresult)\<\{ `DepositPair`: ``"VOID"`` \| \{ `Parent`: \{ `Child`: ``"VOID"`` \| \{ `Value`: \{ `pair`: \{ `a`: `bigint` ; `b`: `bigint` } } } } } ; `ident`: `string` ; `orderAddresses`: \{ `alternate`: ``null`` \| `string` ; `destination`: \{ `credentials`: \{ `paymentKey`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } ; `stakingKey`: ``null`` \| \{ `value`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } } } ; `datum`: ``null`` \| `string` } } ; `scooperFee`: `bigint` }\>

An object containing the hash of the inline datum, the inline datum itself,
and the schema of the original datum.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:96](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L96)

___

### buildSwapDatum

**buildSwapDatum**(`params`): [`TDatumResult`](../modules/Core.md#tdatumresult)\<\{ `ident`: `string` ; `orderAddresses`: \{ `alternate`: ``null`` \| `string` ; `destination`: \{ `credentials`: \{ `paymentKey`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } ; `stakingKey`: ``null`` \| \{ `value`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } } } ; `datum`: ``null`` \| `string` } } ; `scooperFee`: `bigint` ; `swapDirection`: \{ `amount`: `bigint` ; `minReceivable`: ``null`` \| `bigint` ; `suppliedAssetIndex`: ``"A"`` \| ``"B"`` } }\>

Constructs a swap datum object based on the provided swap arguments.
The function initializes a new datum with specific properties such as the pool ident,
order addresses, scooper fee, and swap direction schema. It then converts this datum
into an inline format and computes its hash using [Blaze.BlazeHelper](Blaze.BlazeHelper.md). The function returns an
object containing the hash of the inline datum, the inline datum itself, and the original
datum schema.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `params` | [`ISwapArguments`](../interfaces/Core.ISwapArguments.md) | The swap arguments required to build the swap datum. |

#### Returns

[`TDatumResult`](../modules/Core.md#tdatumresult)\<\{ `ident`: `string` ; `orderAddresses`: \{ `alternate`: ``null`` \| `string` ; `destination`: \{ `credentials`: \{ `paymentKey`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } ; `stakingKey`: ``null`` \| \{ `value`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } } } ; `datum`: ``null`` \| `string` } } ; `scooperFee`: `bigint` ; `swapDirection`: \{ `amount`: `bigint` ; `minReceivable`: ``null`` \| `bigint` ; `suppliedAssetIndex`: ``"A"`` \| ``"B"`` } }\>

An object containing the hash of the inline datum, the inline datum itself,
and the schema of the original datum.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:62](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L62)

___

### buildWithdrawDatum

**buildWithdrawDatum**(`params`): [`TDatumResult`](../modules/Core.md#tdatumresult)\<\{ `WithdrawAsset`: ``"VOID"`` \| \{ `LPToken`: \{ `value`: `bigint` } } ; `ident`: `string` ; `orderAddresses`: \{ `alternate`: ``null`` \| `string` ; `destination`: \{ `credentials`: \{ `paymentKey`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } ; `stakingKey`: ``null`` \| \{ `value`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } } } ; `datum`: ``null`` \| `string` } } ; `scooperFee`: `bigint` }\>

Generates a withdraw datum object from the specified withdraw arguments. This function constructs
a new datum with defined attributes such as the pool ident, order addresses, scooper fee, and
the schema for the supplied LP (Liquidity Provider) asset for withdrawal. After constructing the datum,
it is converted into an inline format, and its hash is calculated using [Blaze.BlazeHelper](Blaze.BlazeHelper.md). The function returns
an object containing the hash of the inline datum, the inline datum itself, and the schema of the original
datum, which are crucial for executing the withdrawal operation within a transactional framework.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `params` | [`IWithdrawArguments`](../interfaces/Core.IWithdrawArguments.md) | The arguments necessary to construct the withdraw datum. |

#### Returns

[`TDatumResult`](../modules/Core.md#tdatumresult)\<\{ `WithdrawAsset`: ``"VOID"`` \| \{ `LPToken`: \{ `value`: `bigint` } } ; `ident`: `string` ; `orderAddresses`: \{ `alternate`: ``null`` \| `string` ; `destination`: \{ `credentials`: \{ `paymentKey`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } ; `stakingKey`: ``null`` \| \{ `value`: \{ `KeyHash`: \{ `value`: `string` } } \| \{ `ScriptHash`: \{ `value`: `string` } } } } ; `datum`: ``null`` \| `string` } } ; `scooperFee`: `bigint` }\>

An object comprising the hash of the inline datum, the inline datum itself,
and the schema of the original datum, facilitating the withdrawal operation's integration into the transactional process.

#### Defined in

[packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts:141](https://github.com/SundaeSwap-finance/sundae-sdk/blob/main/packages/core/src/DatumBuilders/DatumBuilder.Blaze.V1.class.ts#L141)
Loading

0 comments on commit d689229

Please sign in to comment.