Skip to content

Commit 07bae18

Browse files
authored
DexAggregator replaces DexRouter (#8)
- Add DexAggregator.mo - Remove DexRouter.mo
1 parent e5fa9eb commit 07bae18

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed
Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import DRC205 "DRC205Types";
44
import ICDex "ICDexTypes";
55

66
module {
7+
public type Timestamp = Nat;
78
public type DexName = Text;
8-
public type TokenStd = DRC205.TokenStd; // #cycles token principal = CF canister
9+
public type TokenStd = DRC205.TokenStd;
910
public type TokenSymbol = Text;
1011
public type TokenInfo = (Principal, TokenSymbol, TokenStd);
1112
public type ListingReferrer = {
@@ -16,23 +17,36 @@ module {
1617
end: ?Time.Time;
1718
nftId: Text;
1819
};
19-
//public type Pair = (Principal, Principal);
20-
public type SwapCanister = Principal;
20+
public type MarketBoard = { #STAGE2; #STAGE1; #STAGE0 };
21+
public type TradingPair = {
22+
pair: PairInfo;
23+
marketBoard: MarketBoard;
24+
score1: Nat; // Max 70
25+
score2: Nat; // Max 20
26+
score3: Nat;
27+
startingOverG1: ?Timestamp;
28+
startingBelowG2: ?Timestamp;
29+
startingBelowG4: ?Timestamp;
30+
createdTime: Timestamp;
31+
updatedTime: Timestamp;
32+
};
33+
public type PairCanister = Principal;
2134
public type PairRequest = {
2235
token0: TokenInfo;
2336
token1: TokenInfo;
2437
dexName: DexName;
2538
};
26-
public type SwapPair = {
39+
public type PairInfo = {
2740
token0: TokenInfo;
2841
token1: TokenInfo;
2942
dexName: DexName;
30-
canisterId: SwapCanister;
43+
canisterId: PairCanister;
3144
feeRate: Float;
3245
};
3346
public type PairResponse = {
34-
pair:SwapPair;
35-
score:Nat;
47+
pair: PairInfo;
48+
score: Nat;
49+
createdTime: Timestamp;
3650
liquidity: ?ICDex.Liquidity2;
3751
sponsored: Bool;
3852
listingReferrers: [(ListingReferrer, Time.Time, Text)];
@@ -63,7 +77,7 @@ module {
6377
content: Text;
6478
start: Time.Time;
6579
end: Time.Time;
66-
pairs: [(DexName, SwapPair, {#token0; #token1})]
80+
pairs: [(DexName, PairInfo, {#token0; #token1})]
6781
};
6882
public type FilledTrade = {counterparty: Txid; token0Value: DRC205.BalanceChange; token1Value: DRC205.BalanceChange; time: Time.Time;};
6983
public type TraderStats = { // Measured in quote token, data[0] is the latest data
@@ -78,15 +92,15 @@ module {
7892
};
7993
public type TraderData = {
8094
dexName: DexName;
81-
pair: SwapCanister;
95+
pair: PairCanister;
8296
quoteToken: {#token0; #token1};
8397
startTime: Time.Time;
8498
data: [TraderStats]; // The latest data is placed at position [0].
8599
endTime: ?Time.Time; // Set at the end of the competition
86100
total: ?(TraderStats, Float);
87101
};
88102
public type TraderDataResponse = {
89-
pair: SwapPair;
103+
pair: PairInfo;
90104
quoteToken: {#token0; #token1};
91105
startTime: Time.Time;
92106
data: [TraderStats];
@@ -95,33 +109,39 @@ module {
95109
};
96110
public type Config = {
97111
SYS_TOKEN: Principal;
98-
CREATION_FEE: Nat; // token
99-
ROUTING_FEE: Nat; // token
100-
DEFAULT_VOLATILITY_LIMIT: Nat; //%
112+
BLACKHOLE: Principal;
113+
ORACLE: Principal;
114+
SCORE_G1: Nat; // 60
115+
SCORE_G2: Nat; // 50
116+
SCORE_G3: Nat; // 30
117+
SCORE_G4: Nat; // 20
101118
};
102119
public type ConfigRequest = {
103-
CREATION_FEE: ?Nat; // token
104-
ROUTING_FEE: ?Nat; // token
105-
DEFAULT_VOLATILITY_LIMIT: ?Nat; //%
120+
SYS_TOKEN: ?Principal;
121+
BLACKHOLE: ?Principal;
122+
ORACLE: ?Principal;
123+
SCORE_G1: ?Nat; // 60
124+
SCORE_G2: ?Nat; // 50
125+
SCORE_G3: ?Nat; // 30
126+
SCORE_G4: ?Nat; // 20
106127
};
107128
public type TrieList<K, V> = {data: [(K, V)]; total: Nat; totalPage: Nat; };
108129
public type Self = actor {
109-
create : shared (_pair: PairRequest) -> async (canister: SwapCanister, initialized: Bool);
110130
getDexList : shared query () -> async [(DexName, Principal)];
111131
getTokens : shared query (_dexName: ?DexName) -> async [TokenInfo];
112132
getCurrencies : shared query () -> async [TokenInfo];
113-
getPairsByToken : shared query (_token: Principal, _dexName: ?DexName) -> async [(SwapCanister, (SwapPair, Nat))];
114-
getPairs : shared query (_dexName: ?DexName, _page: ?Nat, _size: ?Nat) -> async TrieList<SwapCanister, (SwapPair, Nat)>;
115-
getPairs2 : shared query (_dexName: ?DexName, _lr: ?Principal, _page: ?Nat, _size: ?Nat) -> async TrieList<SwapCanister, PairResponse>;
116-
route : shared query (_token0: Principal, _token1: Principal, _dexName: ?DexName) -> async [(SwapCanister, (SwapPair, Nat))];
133+
getPairsByToken : shared query (_token: Principal, _dexName: ?DexName) -> async [(PairCanister, TradingPair)];
134+
getPairs : shared query (_dexName: ?DexName, _page: ?Nat, _size: ?Nat) -> async TrieList<PairCanister, TradingPair>;
135+
getPairs2 : shared query (_dexName: ?DexName, _lr: ?Principal, _page: ?Nat, _size: ?Nat) -> async TrieList<PairCanister, PairResponse>;
136+
route : shared query (_token0: Principal, _token1: Principal, _dexName: ?DexName) -> async [(PairCanister, TradingPair)];
117137
putByDex : shared (_token0: TokenInfo, _token1: TokenInfo, _canisterId: Principal) -> async ();
118138
removeByDex : shared (_pairCanister: Principal) -> async ();
119-
pushCompetitionByPair : shared (_round: Nat, _name: Text, _start: Time.Time, _end: Time.Time) -> async ();
139+
// pushCompetitionByPair : shared (_round: Nat, _name: Text, _start: Time.Time, _end: Time.Time) -> async ();
120140
pushCompetitionByDex : shared (_id: ?Nat, _name: Text, _content: Text, _start: Time.Time, _end: Time.Time, pairs: [(DexName, Principal, {#token0; #token1})]) -> async Nat;
121141
verifyListingReferrer : shared (_referrer: Principal, _name: Text, _verified: Bool) -> async ();
122142
setListingReferrerByNft : shared (_name: Text, _nftId: Text) -> async ();
123-
propose : shared (_pair: SwapCanister) -> async ();
143+
propose : shared (_pair: PairCanister) -> async ();
124144
listingReferrer : shared query (_referrer: Principal) -> async (_valid: Bool, verified: Bool);
125-
getPairListingReferrers : shared query (_pair: SwapCanister) -> async (sponsored: Bool, listingReferrers: [(ListingReferrer, Time.Time, Text)]);
145+
getPairListingReferrers : shared query (_pair: PairCanister) -> async (sponsored: Bool, listingReferrers: [(ListingReferrer, Time.Time, Text)]);
126146
};
127147
};

0 commit comments

Comments
 (0)