Skip to content

Commit

Permalink
DexAggregator replaces DexRouter (#8)
Browse files Browse the repository at this point in the history
- Add DexAggregator.mo
- Remove DexRouter.mo
  • Loading branch information
iclighthouse authored Jan 27, 2024
1 parent e5fa9eb commit 07bae18
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions src/DexRouter.mo → src/DexAggregator.mo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import DRC205 "DRC205Types";
import ICDex "ICDexTypes";

module {
public type Timestamp = Nat;
public type DexName = Text;
public type TokenStd = DRC205.TokenStd; // #cycles token principal = CF canister
public type TokenStd = DRC205.TokenStd;
public type TokenSymbol = Text;
public type TokenInfo = (Principal, TokenSymbol, TokenStd);
public type ListingReferrer = {
Expand All @@ -16,23 +17,36 @@ module {
end: ?Time.Time;
nftId: Text;
};
//public type Pair = (Principal, Principal);
public type SwapCanister = Principal;
public type MarketBoard = { #STAGE2; #STAGE1; #STAGE0 };
public type TradingPair = {
pair: PairInfo;
marketBoard: MarketBoard;
score1: Nat; // Max 70
score2: Nat; // Max 20
score3: Nat;
startingOverG1: ?Timestamp;
startingBelowG2: ?Timestamp;
startingBelowG4: ?Timestamp;
createdTime: Timestamp;
updatedTime: Timestamp;
};
public type PairCanister = Principal;
public type PairRequest = {
token0: TokenInfo;
token1: TokenInfo;
dexName: DexName;
};
public type SwapPair = {
public type PairInfo = {
token0: TokenInfo;
token1: TokenInfo;
dexName: DexName;
canisterId: SwapCanister;
canisterId: PairCanister;
feeRate: Float;
};
public type PairResponse = {
pair:SwapPair;
score:Nat;
pair: PairInfo;
score: Nat;
createdTime: Timestamp;
liquidity: ?ICDex.Liquidity2;
sponsored: Bool;
listingReferrers: [(ListingReferrer, Time.Time, Text)];
Expand Down Expand Up @@ -63,7 +77,7 @@ module {
content: Text;
start: Time.Time;
end: Time.Time;
pairs: [(DexName, SwapPair, {#token0; #token1})]
pairs: [(DexName, PairInfo, {#token0; #token1})]
};
public type FilledTrade = {counterparty: Txid; token0Value: DRC205.BalanceChange; token1Value: DRC205.BalanceChange; time: Time.Time;};
public type TraderStats = { // Measured in quote token, data[0] is the latest data
Expand All @@ -78,15 +92,15 @@ module {
};
public type TraderData = {
dexName: DexName;
pair: SwapCanister;
pair: PairCanister;
quoteToken: {#token0; #token1};
startTime: Time.Time;
data: [TraderStats]; // The latest data is placed at position [0].
endTime: ?Time.Time; // Set at the end of the competition
total: ?(TraderStats, Float);
};
public type TraderDataResponse = {
pair: SwapPair;
pair: PairInfo;
quoteToken: {#token0; #token1};
startTime: Time.Time;
data: [TraderStats];
Expand All @@ -95,33 +109,39 @@ module {
};
public type Config = {
SYS_TOKEN: Principal;
CREATION_FEE: Nat; // token
ROUTING_FEE: Nat; // token
DEFAULT_VOLATILITY_LIMIT: Nat; //%
BLACKHOLE: Principal;
ORACLE: Principal;
SCORE_G1: Nat; // 60
SCORE_G2: Nat; // 50
SCORE_G3: Nat; // 30
SCORE_G4: Nat; // 20
};
public type ConfigRequest = {
CREATION_FEE: ?Nat; // token
ROUTING_FEE: ?Nat; // token
DEFAULT_VOLATILITY_LIMIT: ?Nat; //%
SYS_TOKEN: ?Principal;
BLACKHOLE: ?Principal;
ORACLE: ?Principal;
SCORE_G1: ?Nat; // 60
SCORE_G2: ?Nat; // 50
SCORE_G3: ?Nat; // 30
SCORE_G4: ?Nat; // 20
};
public type TrieList<K, V> = {data: [(K, V)]; total: Nat; totalPage: Nat; };
public type Self = actor {
create : shared (_pair: PairRequest) -> async (canister: SwapCanister, initialized: Bool);
getDexList : shared query () -> async [(DexName, Principal)];
getTokens : shared query (_dexName: ?DexName) -> async [TokenInfo];
getCurrencies : shared query () -> async [TokenInfo];
getPairsByToken : shared query (_token: Principal, _dexName: ?DexName) -> async [(SwapCanister, (SwapPair, Nat))];
getPairs : shared query (_dexName: ?DexName, _page: ?Nat, _size: ?Nat) -> async TrieList<SwapCanister, (SwapPair, Nat)>;
getPairs2 : shared query (_dexName: ?DexName, _lr: ?Principal, _page: ?Nat, _size: ?Nat) -> async TrieList<SwapCanister, PairResponse>;
route : shared query (_token0: Principal, _token1: Principal, _dexName: ?DexName) -> async [(SwapCanister, (SwapPair, Nat))];
getPairsByToken : shared query (_token: Principal, _dexName: ?DexName) -> async [(PairCanister, TradingPair)];
getPairs : shared query (_dexName: ?DexName, _page: ?Nat, _size: ?Nat) -> async TrieList<PairCanister, TradingPair>;
getPairs2 : shared query (_dexName: ?DexName, _lr: ?Principal, _page: ?Nat, _size: ?Nat) -> async TrieList<PairCanister, PairResponse>;
route : shared query (_token0: Principal, _token1: Principal, _dexName: ?DexName) -> async [(PairCanister, TradingPair)];
putByDex : shared (_token0: TokenInfo, _token1: TokenInfo, _canisterId: Principal) -> async ();
removeByDex : shared (_pairCanister: Principal) -> async ();
pushCompetitionByPair : shared (_round: Nat, _name: Text, _start: Time.Time, _end: Time.Time) -> async ();
// pushCompetitionByPair : shared (_round: Nat, _name: Text, _start: Time.Time, _end: Time.Time) -> async ();
pushCompetitionByDex : shared (_id: ?Nat, _name: Text, _content: Text, _start: Time.Time, _end: Time.Time, pairs: [(DexName, Principal, {#token0; #token1})]) -> async Nat;
verifyListingReferrer : shared (_referrer: Principal, _name: Text, _verified: Bool) -> async ();
setListingReferrerByNft : shared (_name: Text, _nftId: Text) -> async ();
propose : shared (_pair: SwapCanister) -> async ();
propose : shared (_pair: PairCanister) -> async ();
listingReferrer : shared query (_referrer: Principal) -> async (_valid: Bool, verified: Bool);
getPairListingReferrers : shared query (_pair: SwapCanister) -> async (sponsored: Bool, listingReferrers: [(ListingReferrer, Time.Time, Text)]);
getPairListingReferrers : shared query (_pair: PairCanister) -> async (sponsored: Bool, listingReferrers: [(ListingReferrer, Time.Time, Text)]);
};
};

0 comments on commit 07bae18

Please sign in to comment.