-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[add] JPYC rinkeby & code refactoring
- Loading branch information
1 parent
b4c614c
commit 79eb526
Showing
88 changed files
with
2,501 additions
and
92,698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
singleQuote: true | ||
semi: true | ||
printWidth: 120 | ||
trailingComma: es5 | ||
tabWidth: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.