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
- Create a Trader canister
- Configure whitelisted trading pairs
- Configure operators
- Send token0 and token1 to Trader Canister
- Enjoy trading
- 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()
orbuyWall()
, he is using funds that have been kept in the Pair canister by the Trader canister, sodepositToPair()
has to be called first, followed byorder()
orbuyWall()
. If you want to get the funds back into the Trader canister, you need to executewithdrawFromPair()
. - 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 executewithdrawFromPair()
and withdraw the funds kept in the Pair canister to the Trader canister.
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!
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
Tools & Dependencies
- dfx: 0.15.3 (https://github.com/dfinity/sdk/releases/tag/0.15.3)
- moc: 0.10.3
- vessel: 0.7.0 (https://github.com/dfinity/vessel/releases/tag/v0.7.0)
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" }
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.