Skip to content

Commit

Permalink
Merge pull request #19 from layerswap/main-dev
Browse files Browse the repository at this point in the history
Main dev
  • Loading branch information
arkoc authored Aug 15, 2024
2 parents 04b4a84 + 606605e commit f79bd5c
Show file tree
Hide file tree
Showing 34 changed files with 2,365 additions and 753 deletions.
6 changes: 3 additions & 3 deletions packages/evm/solidity/contracts/HashedTimeLockERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ contract HashedTimeLockERC20 {
);
}

function lockCommitment(bytes32 commitId, bytes32 hashlock) external _committed(commitId) returns (bytes32 lockId) {
function lockCommitment(bytes32 commitId, bytes32 hashlock, uint256 timelock) external _committed(commitId) returns (bytes32 lockId) {
lockId = hashlock;
if (commits[commitId].uncommitted == true) {
revert AlreadyUncommitted();
Expand All @@ -250,7 +250,7 @@ contract HashedTimeLockERC20 {
hashlock,
0x0,
commits[commitId].amount,
commits[commitId].timelock,
timelock,
commits[commitId].tokenContract,
false,
false
Expand All @@ -265,7 +265,7 @@ contract HashedTimeLockERC20 {
commits[commitId].srcReceiver,
commits[commitId].srcAsset,
commits[commitId].amount,
commits[commitId].timelock,
timelock,
commits[commitId].messenger,
commitId,
commits[commitId].tokenContract
Expand Down
6 changes: 3 additions & 3 deletions packages/evm/solidity/contracts/HashedTimeLockEther.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ contract HashedTimeLockEther {
return true;
}

function lockCommitment(bytes32 commitId, bytes32 hashlock) external _committed(commitId) returns (bytes32 lockId) {
function lockCommitment(bytes32 commitId, bytes32 hashlock, uint256 timelock) external _committed(commitId) returns (bytes32 lockId) {
lockId = hashlock;
if (commits[commitId].uncommitted == true) {
revert AlreadyUncommitted();
Expand All @@ -220,7 +220,7 @@ contract HashedTimeLockEther {
hashlock,
0x0,
commits[commitId].amount,
commits[commitId].timelock,
timelock,
false,
false
);
Expand All @@ -234,7 +234,7 @@ contract HashedTimeLockEther {
commits[commitId].srcReceiver,
commits[commitId].srcAsset,
commits[commitId].amount,
commits[commitId].timelock,
timelock,
commits[commitId].messenger,
commitId
);
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/solidity/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
chainId: 59141,
},
optimismSepolia: {
url: "https://optimism-sepolia.drpc.org",
url: "https://sepolia.optimism.io",
accounts: ['e9ac8d073f52df4c776f16915460806dc5c28c9bc9b510ad074c275c8cff89e9'],
chainId: 11155420,
},
Expand Down
70 changes: 70 additions & 0 deletions packages/solana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Disclaimer: Development in Progress

Please note that this project is actively under development. It is not ready for deployment on any mainnet environments.
As we continue to experiment and test new ideas, expect significant changes to the interface. Please be prepared for ongoing modifications.

# Hashed Timelock Contracts (HTLCs)

This part of the repository contains anchor solana programs (smart contracts) for implementing Hashed Timelock Contracts (HTLCs) on Solana both for spl Token and sol transactions.
This programs enable users to create, manage, and interact with HTLCs, facilitating secure and trustless transactions. The programs include functions such as creating new HTLCs, redeeming funds locked in HTLCs with a secret hash, and refunding funds in case of expiration or non-redeem. Users can refer to the program's source code and documentation for detailed information on each function's usage and parameters.

## Programs Overview

### HashedTimelock.sol

**Description**: This program allows users to create HTLCs and PHTLCs on Solana for spl token/sol transactions. It follows a protocol where a sender can create a new HTLC for a specific spl token/sol, a receiver can claim the spl/sol after revealing the secret, and the sender can refund the spl/sol if the time lock expires.

#### Functions

- **commit**: Allows a sender to create a new PHTLC for spl tokens by specifying the receiver, messenger, timelock, token contract, and amount.
- **lock**: Allows a sender to create a new HTLC for spl tokens by specifying the receiver, hashlock, timelock, token contract, and amount.
- **redeem**: Allows the receiver to claim the spl tokens locked in the HTLC by providing the secret hash.
- **lockCommit**: Allows the messenger to lock the commited funds by the given hashlock.
- **unlock**: Allows the sender to unlock the spl tokens if the timelock expires and the receiver has not redeemed the funds.
- **uncommit**: Allows the sender to uncommit the spl tokens if the timelock expires and the messenger has not locked the funds.
- **getLockDetails/getCommitDetails**: Retrieves details of a specific HTLC/PHTLC by its contract ID.


## Deployment

### Prerequisites

- solana and anchor installed
- Solana network connection (e.g., localhost, devnet, etc.)
- Sol or test tokens for deployment gas fees

### Steps

1. Clone this repository:

```bash
git clone <repository_url>

2. Navigate to the project directory:

```bash
cd <project_directory>
3. Build Program:
```bash
anchor build

4. Deploy the program
```bash
anchor deploy
5. Test the contracts:
```bash
anchor test/anchor test --skip-local-validator --skip-deploy (To not to redploy the program).

Usage
Once deployed, users can interact with the contracts using Solana wallets or through contract function calls programmatically.

For HashedTimelockERC20.cairo: Users can create HTLCs for ERC20 tokens, redeem tokens, and request refunds.
Refer to the contract source code for function details and usage instructions.

## Acknowledgements

- The initial Anchor implementation was based on the work done in the safe-pay project (https://github.com/PirosB3/SafePaySolana)
2 changes: 1 addition & 1 deletion packages/solana/sol/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolution = true
skip-lint = false

[programs.devnet]
native = "FHNm9iB3sE6rJ2kFyj4URGS3FGpYim6vjGtd1kdc5Mws"
native = "DuHWoXCyDCQBa7oMkZBhvPBJYsPKbuUmusZBeK8vdBtN"

[registry]
url = "https://api.apr.dev"
Expand Down
Loading

0 comments on commit f79bd5c

Please sign in to comment.