Skip to content

Commit

Permalink
simplify entrypoint names
Browse files Browse the repository at this point in the history
  • Loading branch information
KStasi committed Jun 23, 2021
1 parent 6261cef commit e687fe6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions contracts/partials/ITTDex.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ type divest_liquidity_params is
]

type dex_action is
| InitializeExchange of invest_liquidity_params (* sets initial liquidity *)
| TokenToTokenRoutePayment of token_to_token_route_params (* exchanges token to another token and sends them to receiver *)
| InvestLiquidity of invest_liquidity_params (* mints min shares after investing tokens *)
| DivestLiquidity of divest_liquidity_params (* burns shares and sends tokens to the owner *)
| AddPair of invest_liquidity_params (* sets initial liquidity *)
| Swap of token_to_token_route_params (* exchanges token to another token and sends them to receiver *)
| Invest of invest_liquidity_params (* mints min shares after investing tokens *)
| Divest of divest_liquidity_params (* burns shares and sends tokens to the owner *)

type use_params is dex_action
type get_reserves_params is record [
Expand Down
8 changes: 4 additions & 4 deletions contracts/partials/TTDex.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ based on the argument type.
const s : full_dex_storage) : full_return is
block {
const idx : nat = case p of
| InitializeExchange(n) -> 0n
| TokenToTokenRoutePayment(n) -> 1n
| InvestLiquidity(n) -> 2n
| DivestLiquidity(n) -> 3n
| AddPair(n) -> 0n
| Swap(n) -> 1n
| Invest(n) -> 2n
| Divest(n) -> 3n
end;
const res : return = case s.dex_lambdas[idx] of
Some(f) -> f(p, s.storage, this)
Expand Down
32 changes: 16 additions & 16 deletions contracts/partials/TTMethodDex.ligo
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function initialize_exchange(
block {
var operations: list(operation) := list[];
case p of
InitializeExchange(params) -> {
AddPair(params) -> {
if s.entered
then failwith("Dex/reentrancy")
else s.entered := True;
Expand Down Expand Up @@ -269,9 +269,9 @@ function initialize_exchange(
params.pair.token_b_type
) # operations;
}
| TokenToTokenRoutePayment(n) -> skip
| InvestLiquidity(n) -> skip
| DivestLiquidity(n) -> skip
| Swap(n) -> skip
| Invest(n) -> skip
| Divest(n) -> skip
end
} with (operations, s)

Expand Down Expand Up @@ -350,8 +350,8 @@ function token_to_token_route(
block {
var operations: list(operation) := list[];
case p of
| InitializeExchange(n) -> skip
| TokenToTokenRoutePayment(params) -> {
| AddPair(n) -> skip
| Swap(params) -> {
if s.entered
then failwith("Dex/reentrancy")
else s.entered := True;
Expand Down Expand Up @@ -431,8 +431,8 @@ function token_to_token_route(
end;
operations := last_operation # operations;
}
| InvestLiquidity(n) -> skip
| DivestLiquidity(n) -> skip
| Invest(n) -> skip
| Divest(n) -> skip
end
} with (operations, s)

Expand All @@ -445,9 +445,9 @@ function invest_liquidity(
block {
var operations: list(operation) := list[];
case p of
| InitializeExchange(n) -> skip
| TokenToTokenRoutePayment(n) -> skip
| InvestLiquidity(params) -> {
| AddPair(n) -> skip
| Swap(n) -> skip
| Invest(params) -> {
if s.entered
then failwith("Dex/reentrancy")
else s.entered := True;
Expand Down Expand Up @@ -539,7 +539,7 @@ function invest_liquidity(
params.pair.token_b_type
) # operations;
}
| DivestLiquidity(n) -> skip
| Divest(n) -> skip
end
} with (operations, s)

Expand All @@ -551,10 +551,10 @@ function divest_liquidity(
block {
var operations: list(operation) := list[];
case p of
| InitializeExchange(token_amount) -> skip
| TokenToTokenRoutePayment(n) -> skip
| InvestLiquidity(n) -> skip
| DivestLiquidity(params) -> {
| AddPair(token_amount) -> skip
| Swap(n) -> skip
| Invest(n) -> skip
| Divest(params) -> {
if s.entered
then failwith("Dex/reentrancy")
else s.entered := True;
Expand Down
6 changes: 3 additions & 3 deletions migrations/2_deploy_token_to_token_dex.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = async (deployer, network, accounts) => {

operation = await dex.methods
.use(
"initializeExchange",
"addPair",
ordered
? token0Instance.address.toString()
: token1Instance.address.toString(),
Expand Down Expand Up @@ -154,7 +154,7 @@ module.exports = async (deployer, network, accounts) => {
if (standard === "MIXED") {
operation = await dex.methods
.use(
"initializeExchange",
"addPair",
ordered
? token0Instance.address.toString()
: token1Instance.address.toString(),
Expand All @@ -171,7 +171,7 @@ module.exports = async (deployer, network, accounts) => {
} else {
operation = await dex.methods
.use(
"initializeExchange",
"addPair",
ordered
? token0Instance.address.toString()
: token1Instance.address.toString(),
Expand Down
10 changes: 5 additions & 5 deletions test/helpers/ttdexFA2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class TTDex extends TokenFA2 {

const operation = await this.contract.methods
.use(
"initializeExchange",
"addPair",
tokenAAddress,
tokenAid,
standard.toLowerCase() == "mixed" ? "fa2" : standard.toLowerCase(),
Expand Down Expand Up @@ -177,7 +177,7 @@ export class TTDex extends TokenFA2 {
}
}
const operation = await this.contract.methods
.use("tokenToTokenRoutePayment", swaps, amountIn, minAmountOut, receiver)
.use("swap", swaps, amountIn, minAmountOut, receiver)
.send();
await confirmOperation(tezos, operation.hash);
return operation;
Expand Down Expand Up @@ -246,7 +246,7 @@ export class TTDex extends TokenFA2 {
},
];
const operation = await this.contract.methods
.use("tokenToTokenRoutePayment", swaps, amountIn, minAmountOut, receiver)
.use("swap", swaps, amountIn, minAmountOut, receiver)
.send();
await confirmOperation(tezos, operation.hash);
return operation;
Expand Down Expand Up @@ -291,7 +291,7 @@ export class TTDex extends TokenFA2 {
}
const operation = await this.contract.methods
.use(
"investLiquidity",
"invest",
pair.token_a_address,
pair.token_a_id,
standard.toLowerCase() == "mixed" ? "fa2" : standard.toLowerCase(),
Expand Down Expand Up @@ -319,7 +319,7 @@ export class TTDex extends TokenFA2 {
let pair = this.storage.tokens[pairId];
const operation = await this.contract.methods
.use(
"divestLiquidity",
"divest",
pair.token_a_address,
pair.token_a_id,
standard.toLowerCase() == "mixed" ? "fa2" : standard.toLowerCase(),
Expand Down

0 comments on commit e687fe6

Please sign in to comment.