Skip to content

ldclabs/ICDex-Trader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 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.

Translated with DeepL.com (free version)

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: 48f27845fa769fde6d3a82fe25824c85d658cff0388e2211c917cccc01aa9fcc
    • Wasm generated by Factory cansiter: a1621015a86ca7e9d860bf2f17296cc4a82935a1f6e54cd2a512e0202b62eab4
  • Version: 0.5.4
  • 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

Languages

  • Motoko 91.1%
  • Dhall 8.9%