Skip to content

Commit

Permalink
[add] JPYC rinkeby & code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
0x070696E65 authored and ymuichiro committed Dec 31, 2022
1 parent b4c614c commit 79eb526
Show file tree
Hide file tree
Showing 88 changed files with 2,501 additions and 92,698 deletions.
108 changes: 3 additions & 105 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,124 +7,22 @@ yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt


# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
# custom
dist
.DS_Store
5 changes: 5 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
singleQuote: true
semi: true
printWidth: 120
trailingComma: es5
tabWidth: 2
98 changes: 79 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,87 @@
<div align="center">
<img src="assets/evm-symbol-swap-logo-wide.png" alt="evm-symbol-swap-logo" title="evm-symbol-swap-logo">
</div>

# EVM <-> Symbol Swap

This package is for HTLC transactions between the EVM blockchain and Symbol.
This package is for HTLC transactions between the EVM blockchain and Symbol. Usage and examples are shown below.

## Chains
## Introduction

Install the necessary libraries

**npm**

```
npm install --save symbol-sdk@2 web3
```

**yarn**

```
yarn add symbol-sdk@2 web3
```

HTLC issues a secret and key in advance and uses this to issue a secret lock.
When both parties agree to the transaction, the secret and key are exchanged separately, and the key is used to receive a token.
This is how the cross-chain swap is performed.

## Issue a secret lock on the Symbol side

You can publish using this package with the following operations.
The output hashPair contains a secret and a proof. The secret is shared in advance, and the proof is issued at a mutually agreed timing.

- ethereum
- polygon
- symbol
```ts
const client = new HTLCSymbolService(
Contracts.symbol.testnet.endpoint,
NetworkType.TEST_NET,
Contracts.symbol.testnet.generationHashSeed,
Contracts.symbol.testnet.epochAdjustment
);
const recipientAccount = Account.createFromPrivateKey(SYMBOL.PRIVATEKEY.TO, NetworkType.TEST_NET);
const senderAccount = Account.createFromPrivateKey(SYMBOL.PRIVATEKEY.FROM, NetworkType.TEST_NET);
const { hashPair, transaction } = client.mint(recipientAccount.address.plain(), SYMBOL.CURRENCY.MOSAIC_ID, 1);
const signedTx = await client.sign(SYMBOL.PRIVATEKEY.FROM, transaction);
```

### Configs
## Symbol side issues secret proof

#### ETH TESTNET EXAMPLE
With a secret lock, locked assets are withdrawn through a secret proof transaction.

```ts
const drawTx = client.withDraw(recipientAccount.address.plain(), hashPair.proof, hashPair.secret);
const signedTx = await client.sign(recipientAccount.privateKey, drawTx);
```

## Issue a secret lock on the EVM side

As when issued with Symbol, the asset is pre-locked and a secret and proof are issued.
The output hashPair contains a secret and a proof.

```ts
const client = new HTLCService(Contracts.sepolia.native.endpoint, Contracts.sepolia.native.contractAddress);
const AccountService = client.web3.eth.accounts;
const fromAddress = AccountService.wallet.add(PRIVATEKEY.FROM).address;
const toAddress = AccountService.wallet.add(PRIVATEKEY.TO).address;
const { result, hashPair } = await client.mint(toAddress, fromAddress, 1);
```

## Secret proofs are issued on the EVM side.

The EVM also withdraws the locked assets when indicating the completion of the transaction.

```ts
const res = await client.withDraw(result.events.LogHTLCNew.returnValues.contractId, toAddress, hashPair.proof);
```

For more detailed examples, please check the sample collection below
[examples](examples/README.md)

## Chains

| key | value |
| -------- | ------------------------------------------------------------- |
| provider | https://sepolia.infura.io/v3/85eb73cb20fc46058b5044657ed33efd |
| htlc | 0x822f315505C67727E3bDC89b8ff7a5cEc3dDEBF7 |
| htlc20 | 0x13cf057B85085972a2FffdB73E952b1F5E850C0d |
| htlc721 | 0x010f8d96C3D3BbA7b3935da8B20AAB3C9E2F6264 |
The following chains are supported

| key | value |
| -------- | ------------------------------------------ |
| provider | https://rpc-mumbai.maticvigil.com |
| htlc | 0x6003028E5C3FB11c5F002902dDa1E18cF6a5D34B |
| htlc20 | 0xa66ffa7b45d9138e6A93bBa1f29a580bd559E5cC |
| htlc721 | 0x7f83a9aA861Aa428088E9323f722F2390654C614 |
- [ethereum](https://ethereum.org/)
- [polygon](https://polygon.technology/)
- [jpyc](https://jpyc.jp/)
- [symbol](https://symbol-community.com/)
Binary file added assets/evm-symbol-swap-logo-wide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/evm-symbol-swap-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 79eb526

Please sign in to comment.