Skip to content

iclighthouse/ICDex-Trader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ICDex-Trader

This is a smart contract for agents to trade on ICDex. There are several main possible application scenarios.

  • A decentralized trader for SNS Treasury

SNS Treasury funds participate in ICDex trading or provide liquidity in a non-custodial manner, maintaining decentralization. Agent moral hazard can be effectively mitigated by transferring SNS Treasury funds to Trader Canister and assigning a non-drawing operator to manage them. Guide>>

  • Delegation to a third-party trader

The owner of the funds delegates to a trader to trade on ICDex in a non-custodial manner without sending funds to him/her.

  • Quantitative trader

Adds a non-withdrawal operator to the Trader, which acts as the account in the quantitative trading program that interacts with the Trader. This effectively prevents the quantitative trading program from losing funds due to private key leakage incidents.

  • Other

Guide

  1. Create a Trader canister
  2. Configure whitelisted trading pairs
  3. Configure operators
  4. Send token0 and token1 to Trader Canister
  5. Enjoy trading
  6. Withdraw token0 and token1

Note:

  • An additional 2x token fee must be retained in the balance of Trader, and the entire amount cannot be used for placing orders.
  • When the operator calls order() or buyWall(), he is using funds that have been kept in the Pair canister by the Trader canister, so depositToPair() has to be called first, followed by order() or buyWall(). If you want to get the funds back into the Trader canister, you need to execute withdrawFromPair().
  • When the operator calls addLiquidity(), the funds in Trader canister are used. If there are insufficient funds in the Trader canister, it is necessary to execute withdrawFromPair() and withdraw the funds kept in the Pair canister to the Trader canister.

Note:

The controller of Trader Canister is the creator, and the Cycles balance of the canister needs to be monitored and topped up by the creator.

WARNING: If the Cycles balance of Trader Canister is insufficient, it may result in the deletion of the canister, which will result in the loss of all assets in the canister. The creator needs to monitor the Cycles balance of the canister at all times!

Docs

Create a Trader canister (Example)

TRADER_CREATION_FEE: 5 ICL

dfx canister --network ic call hhaaz-2aaaa-aaaaq-aacla-cai icrc2_approve '(record{ spender = record{owner = principal "ibnyg-oiaaa-aaaar-qaa3q-cai"; subaccount = null }; amount = 10_000_000_000: nat })'

dfx canister --network ic call ibnyg-oiaaa-aaaar-qaa3q-cai create '("Trader-1", principal "__trading_pair_canister-id__", null, null)'

Test (_trading_pair_canister-id_): xjazg-fiaaa-aaaar-qacrq-cai

Canisters

Tools & Dependencies

Trader Factory

  • Canister-id: ibnyg-oiaaa-aaaar-qaa3q-cai (Mainnet)

Trader Example

  • Canister-id: cirzd-3aaaa-aaaak-afk2q-cai (Test)
  • Module hash:
    • Wasm compiled with dfx: e41a6a2f7e34b987e045f08a0d1804cb6f5976625a00a3882927dda73de4e4e9
    • Wasm generated by Factory cansiter: e3a4790f89545b3352c7c218780c6bcd317b18de0486b98946a4990bc2db6264
  • Version: 0.5.5
  • Build: { "args": "--compacting-gc" }

Disclaimer

ICDex-Trader is an open source trading tool for technical reference only. Use it only after you understand the technical background and risks involved, and you need to bear all the consequences resulting from the use of this tool.

About

Trader agent contract on ICDex

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published