Skip to content

Commit

Permalink
feat: add graph url, change account interface, upgrade starknetjs ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
0xKermo committed Mar 11, 2024
1 parent c3ea891 commit 1aa5549
Show file tree
Hide file tree
Showing 9 changed files with 4,687 additions and 4,663 deletions.
Binary file added .DS_Store
Binary file not shown.
15 changes: 5 additions & 10 deletions examples/src/account.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { Account, CairoVersion, Provider } from "starknet";
import { Account, CairoVersion, Provider, RpcProvider } from "starknet";

export function account(
privateKey: string,
public_key: string,
isCairo1: string,
rpc_url: string,
) {
enum NetworkName {
SN_MAIN = "SN_MAIN",
SN_GOERLI = "SN_GOERLI",
SN_GOERLI2 = "SN_GOERLI2",
}
const provider = new Provider({
sequencer: {
network: NetworkName.SN_MAIN,
},

const provider = new RpcProvider({
nodeUrl: rpc_url,
});
const account0 = new Account(
provider,
Expand Down
15 changes: 8 additions & 7 deletions examples/src/buildTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from "@ethersproject/bignumber";
import { Router as FibrousRouter } from "fibrous-router-sdk";
import { Router as FibrousRouter } from "../../src/router";
import { parseUnits } from "ethers";
import { Call } from "starknet";

Expand All @@ -15,28 +15,29 @@ async function main() {
const tokenInAddress = tokens["usdt"].address;
const tokenOutAddress = tokens["usdc"].address;
const tokenInDecimals = tokens["usdt"].decimals;
const inputAmount = BigNumber.from(parseUnits("1000", tokenInDecimals));
const inputAmount = BigNumber.from(parseUnits("5", tokenInDecimals));

// Call the buildTransaction method in order to build the transaction
// slippage: The maximum acceptable slippage of the buyAmount amount.
// slippage formula = slippage * 100
// value 0.005 is %0.5, 0.05 is 5%, 0.01 is %1, 0.001 is %0.1 ...
const slippage = 0.005;
const receiverAddress = "account address";
const destination = "account_address";
const swapCall = await fibrous.buildTransaction(
inputAmount,
tokenInAddress,
tokenOutAddress,
slippage,
receiverAddress,
destination,
);
console.log(swapCall);
const public_key = "account public key";
const privateKey = "account private key";
const public_key = "public_key";
const privateKey = "private_key";

// https://www.starknetjs.com/docs/guides/connect_account
// If this account is based on a Cairo v2 contract (for example OpenZeppelin account 0.7.0 or later), do not forget to add the parameter "1" after the privateKey parameter
const account0 = account(privateKey, public_key, "1");
const RPC_URL = "RPC_URL";
const account0 = account(privateKey, public_key, "1", RPC_URL);
const approveCall:Call = await fibrous.buildApprove(
inputAmount,
tokenInAddress,
Expand Down
4 changes: 4 additions & 0 deletions examples/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ async function main() {
const tokenOutAddress = tokens["usdc"].address;
const tokenInDecimals = tokens["eth"].decimals;
const inputAmount = BigNumber.from(parseUnits("1", tokenInDecimals));
const reverse = false;
// Converting 1 ETH to USDC
const route = await fibrous.getBestRoute(
inputAmount,
tokenInAddress,
tokenOutAddress,
{
reverse,
},
);
console.log("route", route);
} catch (error) {
Expand Down
134 changes: 73 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@ethersproject/bignumber": "^5.7.0",
"ethers": "^6.7.1",
"fibrous-router-sdk": "^0.3.4",
"starknet": "^5.14.1"
"starknet": "^5.24.3"
},
"publishConfig": {
"access": "public"
Expand Down
5 changes: 3 additions & 2 deletions src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { BigNumber } from "@ethersproject/bignumber";
import { Call } from "starknet";
export class Router {
readonly DEFAULT_API_URL = "https://api.fibrous.finance";
readonly GRAPH_API_URL = "https://graph.fibrous.finance";
readonly ROUTER_ADDRESS =
"0x00f6f4CF62E3C010E0aC2451cC7807b5eEc19a40b0FaaCd00CCA3914280FDf5a";

Expand Down Expand Up @@ -68,13 +69,13 @@ export class Router {
* @returns Supported token list
*/
async supportedTokens(): Promise<Record<string, Token>> {
const tokens: Token[] = await fetch(`${this.apiUrl}/tokens`, {
const tokens: Token[] = await fetch(`${this.GRAPH_API_URL}/tokens`, {
headers: buildHeaders(this.apiKey),
}).then((response) => response.json());

// Create a record of tokens by symbol
return tokens.reduce(
(acc, token) => Object.assign(acc, { [token.symbol]: token }),
(acc, token) => Object.assign(acc, { [token.symbol.toLocaleLowerCase()]: token }),
{},
);
}
Expand Down
7 changes: 6 additions & 1 deletion src/types/enums.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
export const Protocols = {
mySwap: 1,
JediSwap: 2,
"10K Swap": 3,
TenKSwap: 3,
SithSwap: 4,
Ekubo: 5,
MyswapCL: 6,
StarkDefi: 7,
JediSwapCL: 8,
Nostra: 9,
Haiko: 10,
} as const;

export type ProtocolId = (typeof Protocols)[keyof typeof Protocols];
Loading

0 comments on commit 1aa5549

Please sign in to comment.