Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DTA-1731] Set up DefilLama adapter #5

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,126 changes: 1,636 additions & 490 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Forc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ source = "member"
dependencies = [
"executor",
"interfaces",
"logger_abi",
"mira_v1_swap",
"std",
"utils",
Expand All @@ -25,6 +26,7 @@ source = "member"
dependencies = [
"executor",
"interfaces",
"logger_abi",
"math",
"mira_v1_swap",
"std",
Expand Down Expand Up @@ -59,6 +61,21 @@ name = "interfaces"
source = "member"
dependencies = ["std"]

[[package]]
name = "logger"
source = "member"
dependencies = [
"logger_abi",
"standards git+https://github.com/FuelLabs/sway-standards?tag=v0.6.1#792639cdf391565e6e6a02482ea8a46d9604a6f5",
"std",
"sway_libs",
]

[[package]]
name = "logger_abi"
source = "member"
dependencies = ["std"]

[[package]]
name = "math"
source = "member"
Expand Down
2 changes: 2 additions & 0 deletions Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ members = [
"dex_lib/mira_v1/interfaces",
"dex_lib/mira_v1/math",
"dex_lib/mira_v1/utils",
"dex_lib/logger_abi",
"scripts/add_liquidity_script",
"scripts/create_pool_and_add_liquidity_script",
"contracts/mocks/mock_token",
"contracts/logger",
"order_utils",
"one_delta_orders",
"order_router",
Expand Down
2 changes: 2 additions & 0 deletions contracts/logger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
10 changes: 10 additions & 0 deletions contracts/logger/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
authors = ["1delta"]
entry = "main.sw"
license = "Apache-2.0"
name = "logger"

[dependencies]
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.6.1" }
sway_libs = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.24.0" }
logger_abi = { path = "../../dex_lib/logger_abi" }
13 changes: 13 additions & 0 deletions contracts/logger/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
contract;

use logger_abi::{Logger, SwapEvent};

impl Logger for Contract {
fn dead_call() {
// do nothing
}

fn log_swap_event(asset: AssetId, amount: u64) {
log(SwapEvent { asset, amount });
}
}
7 changes: 7 additions & 0 deletions dex_lib/logger_abi/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
authors = ["1delta"]
entry = "main.sw"
license = "Apache-2.0"
name = "logger_abi"

[dependencies]
11 changes: 11 additions & 0 deletions dex_lib/logger_abi/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library;

pub struct SwapEvent {
pub asset: AssetId,
pub amount: u64,
}

abi Logger {
fn dead_call();
fn log_swap_event(asset: AssetId, amount: u64);
}
3 changes: 3 additions & 0 deletions fuels.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { createConfig } from 'fuels';
import { PRIVATE_KEY, RPC } from "./env"

export default createConfig({
contracts: [
"./contracts/logger"
],
scripts: [
"./scripts/batch_swap_exact_in_script",
"./scripts/batch_swap_exact_out_script"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "forc build",
"abis": "./tools/fetch_abis.sh",
"test:rs": "cargo test",
"types": "fuels typegen -i scripts/*/out/*/*-abi.json -o ./ts-scripts/typegen --script & fuels typegen -i fixtures/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i one_delta_orders/*/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i order_router/*/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i contracts/mocks/mock_token/*/*/*-abi.json -o ./ts-scripts/typegen --contract"
"types": "fuels typegen -i scripts/*/out/*/*-abi.json -o ./ts-scripts/typegen --script & fuels typegen -i fixtures/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i one_delta_orders/*/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i order_router/*/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i contracts/mocks/mock_token/*/*/*-abi.json -o ./ts-scripts/typegen --contract & fuels typegen -i contracts/logger/*/*/*-abi.json -o ./ts-scripts/typegen --contract",
"deploy:logger": "tsx ts-scripts/mainnet/logger/deploy.ts"
},
"keywords": [],
"author": "1delta",
Expand Down
2 changes: 2 additions & 0 deletions scripts/batch_swap_exact_in_script/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ executor = { path = "../../dex_lib/executor" }
interfaces = { path = "../../dex_lib/mira_v1/interfaces" }
mira_v1_swap = { path = "../../dex_lib/mira_v1/swap" }
utils = { path = "../../dex_lib/mira_v1/utils" }
logger_abi = { path = "../../dex_lib/logger_abi" }

6 changes: 6 additions & 0 deletions scripts/batch_swap_exact_in_script/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use interfaces::mira_amm::MiraAMM;
use utils::blockchain_utils::check_deadline;
use executor::{BatchSwapStep, execute_exact_in, get_dex_input_receiver};
use std::asset::transfer;
use logger_abi::Logger;

////////////////////////////////////////////////////
// Error codes
Expand All @@ -16,6 +17,7 @@ const EMPTY_PATH_ENTRY: u64 = 100;
configurable {
MIRA_AMM_CONTRACT_ID: ContractId = ContractId::from(0x2e40f2b244b98ed6b8204b3de0156c6961f98525c8162f80162fcf53eebd90e7),
ONE_DELTA_ORDERS_CONTRACT_ID: ContractId = ContractId::from(0xf6caa75386fe9ba4da15b82723ecffb0d56b28ae7ece396b15c5650b605359ac),
LOGGER_CONTRACT_ID: ContractId = ContractId::from(0x60caa3fe777329cd32a66a4c7ac5840e4eb10441a1f8331cd00d45fb0341a7a6),
}

// Swap split paths exact in
Expand Down Expand Up @@ -114,4 +116,8 @@ fn main(
// increment path index
i += 1;
}

// call dead_call on logger to make this TX traceable
let logger = abi(Logger, LOGGER_CONTRACT_ID.into());
logger.dead_call();
}
1 change: 1 addition & 0 deletions scripts/batch_swap_exact_out_script/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ interfaces = { path = "../../dex_lib/mira_v1/interfaces" }
mira_v1_swap = { path = "../../dex_lib/mira_v1/swap" }
math = { path = "../../dex_lib/mira_v1/math" }
utils = { path = "../../dex_lib/mira_v1/utils" }
logger_abi = { path = "../../dex_lib/logger_abi" }
6 changes: 6 additions & 0 deletions scripts/batch_swap_exact_out_script/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ script;
use executor::{BatchSwapStep, calculate_amounts_exact_out_and_fund, forward_swap_exact_out};
use utils::blockchain_utils::check_deadline;
use std::asset::transfer;
use logger_abi::Logger;

////////////////////////////////////////////////////
// Error codes
Expand All @@ -15,6 +16,7 @@ const EMPTY_PATH_ENTRY: u64 = 100;
configurable {
MIRA_AMM_CONTRACT_ID: ContractId = ContractId::from(0x2e40f2b244b98ed6b8204b3de0156c6961f98525c8162f80162fcf53eebd90e7),
ONE_DELTA_ORDERS_CONTRACT_ID: ContractId = ContractId::from(0xf6caa75386fe9ba4da15b82723ecffb0d56b28ae7ece396b15c5650b605359ac),
LOGGER_CONTRACT_ID: ContractId = ContractId::from(0x60caa3fe777329cd32a66a4c7ac5840e4eb10441a1f8331cd00d45fb0341a7a6),
}

fn main(
Expand Down Expand Up @@ -46,4 +48,8 @@ fn main(
);
i += 1;
}

// call dead_call on logger to make this TX traceable
let logger = abi(Logger, LOGGER_CONTRACT_ID.into());
logger.dead_call();
}
24 changes: 24 additions & 0 deletions ts-scripts/mainnet/logger/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Provider, Wallet } from "fuels";
import { MainnetData } from "../../contexts";
import { PRIVATE_KEY } from "../../../env";
import { LoggerFactory } from "../../typegen/LoggerFactory";

async function main() {
const provider = await Provider.create(MainnetData.RPC);

const wallet = Wallet.fromPrivateKey(PRIVATE_KEY!, provider);

const Logger = await LoggerFactory.deploy(wallet)

const LoggerAddress = Logger.contractId
console.log(LoggerAddress)
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

// latest deployoment: 0x60caa3fe777329cd32a66a4c7ac5840e4eb10441a1f8331cd00d45fb0341a7a6