Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bnUSD #5

Open
CyrusVorwald opened this issue Aug 4, 2024 · 0 comments
Open

Implement bnUSD #5

CyrusVorwald opened this issue Aug 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@CyrusVorwald
Copy link
Contributor

Overview

bnUSD is a token contract that burns instead of locks on the source chain when sending cross-chain.

Example Usage

Alice has 1000 bnUSD on Stacks and wants to send 500 bnUSD to Bob's Ethereum address.

(cross-transfer "0x1.eth/0x742d35Cc6634C0532925a3b844Bc454e4438f44e" u500000000 none)

500 bnUSD is burned from Alice's account on Stacks and the following RLP-encoded cross-chain message is sent to Ethereum via xCall.

{
  "method": "xCrossTransfer",
  "from": "0x1.stx/SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",  // Alice's Stacks address
  "to": "0x1.eth/0x742d35Cc6634C0532925a3b844Bc454e4438f44e",  // Bob's Ethereum address
  "amount": 500000000,
  "data": null  // No additional data
}

On Ethereum, the bnUSD contract receives this message and mints 500 bnUSD to Bob's address.

If the transfer fails on Ethereum for any reason, a revert message would be sent back to Stacks to mint 500 bnUSD back to Alice's address:

{
  "method": "xCrossTransferRevert",
  "to": "SP2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKNRV9EJ7",  // Alice's Stacks address
  "amount": 500000000
}

Requirements

Implement RLP encoding/decoding for the following cross-chain messages:

;; Asset Transfer Message
;; For sending assets to other chains
(define-data-var transfer-message
  (tuple
    (method (string-ascii 13))      ;; "xCrossTransfer"
    (from (string-ascii 42))
    (to (string-ascii 42))
    (amount uint)
    (data (optional (buff 256)))
  )
)

;; Asset Transfer Revert Message
;; For handling failed transfers
(define-data-var transfer-revert-message
  (tuple
    (method (string-ascii 19))      ;; "xCrossTransferRevert"
    (to principal)
    (amount uint)
  )
)

Implement handle-call-message:

(define-public (handle-call-message (from (string-ascii 64)) (data (buff 1024)) (protocols (list 10 (string-ascii 64))))
  (begin
    ;; Implementation
    ;; 1. Verify the message source and protocols
    ;; 2. Decode the message data
    ;; 3. Route to the appropriate function (transfer or revert)
    (ok true)
  )
)

Implement cross-transfer:

(define-public (cross-transfer (to (string-ascii 42)) (amount uint) (data (optional (buff 256))))
  (begin
    ;; Implementation
    ;; 1. Burn tokens from sender
    ;; 2. Prepare cross-chain message
    ;; 3. Call xCall service to send the message
    (ok true)
  )
)
@CyrusVorwald CyrusVorwald added the enhancement New feature or request label Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant