Skip to content

Commit

Permalink
Merge pull request #1867 from DefiLlama/sunswap
Browse files Browse the repository at this point in the history
add sunswap fees
  • Loading branch information
dtmkeng authored Sep 5, 2024
2 parents 4b5f85e + d25a0d2 commit 791972e
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
34 changes: 34 additions & 0 deletions fees/sunswap-v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { time } from "console";
import { Adapter, FetchOptions, } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { httpGet } from "../utils/fetchURL";

const api = "https://openapi.sun.io/open/api/feeData"
interface IResponse {
date: number;
fee: number;
}

const adapter: Adapter = {
version: 1,
adapter: {
[CHAIN.TRON]: {
fetch: (async (_t: any, _a: any ,options: FetchOptions) => {
const start = options.startOfDay * 1000;
const end = start + 86400;
const startStr = new Date(start).toISOString().split("T")[0];
const endStr = new Date(end).toISOString().split("T")[0];
const url = `${api}?fromDate=${startStr}&toDate=${endStr}&version=v1`;
const res: IResponse[] = (await httpGet(url)).data;
const dailyFees = options.createBalances();
const dayItem = res.find((item) => item.date === start);
dailyFees.addGasToken((dayItem?.fee || 0) * 1e6);
return { dailyFees, timestamp: options.startOfDay };
}) as any,
start: 1704560436
},
},

}

export default adapter;
33 changes: 33 additions & 0 deletions fees/sunswap-v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { time } from "console";
import { Adapter, FetchOptions, } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { httpGet } from "../utils/fetchURL";

const api = "https://openapi.sun.io/open/api/feeData"
interface IResponse {
date: number;
fee: number;
}

const adapter: Adapter = {
version: 1,
adapter: {
[CHAIN.TRON]: {
fetch: (async (_t: any, _a: any ,options: FetchOptions) => {
const start = options.startOfDay * 1000;
const end = start + 86400;
const startStr = new Date(start).toISOString().split("T")[0];
const endStr = new Date(end).toISOString().split("T")[0];
const url = `${api}?fromDate=${startStr}&toDate=${endStr}&version=v2`;
const res: IResponse[] = (await httpGet(url)).data;
const dayItem = res.find((item) => item.date === start);
const dailyFees = dayItem?.fee || 0;
return { dailyFees, timestamp: options.startOfDay };
}) as any,
start: 1704560436
},
},

}

export default adapter;
33 changes: 33 additions & 0 deletions fees/sunswap-v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { time } from "console";
import { Adapter, FetchOptions, } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { httpGet } from "../utils/fetchURL";

const api = "https://openapi.sun.io/open/api/feeData"
interface IResponse {
date: number;
fee: number;
}

const adapter: Adapter = {
version: 1,
adapter: {
[CHAIN.TRON]: {
fetch: (async (_t: any, _a: any ,options: FetchOptions) => {
const start = options.startOfDay * 1000;
const end = start + 86400;
const startStr = new Date(start).toISOString().split("T")[0];
const endStr = new Date(end).toISOString().split("T")[0];
const url = `${api}?fromDate=${startStr}&toDate=${endStr}&version=v3`;
const res: IResponse[] = (await httpGet(url)).data;
const dayItem = res.find((item) => item.date === start);
const dailyFees = dayItem?.fee || 0;
return { dailyFees, timestamp: options.startOfDay };
}) as any,
start: 1704560436
},
},

}

export default adapter;

0 comments on commit 791972e

Please sign in to comment.