From fecc6c763b5a6900ff289e10f642d9a98e853c09 Mon Sep 17 00:00:00 2001 From: Kris Urbas Date: Wed, 27 May 2020 16:54:08 +0200 Subject: [PATCH 1/2] fix exports and improve kyber docs --- docs/kyber.md | 26 ++++++++++---------------- src/idle/index.ts | 2 +- src/kyber/index.ts | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/docs/kyber.md b/docs/kyber.md index 9d97166..b14f742 100644 --- a/docs/kyber.md +++ b/docs/kyber.md @@ -44,9 +44,7 @@ contract KyberNetworkProxy is KyberNetworkProxyInterface, SimpleNetworkInterface ```js const { ethers } = require("ethers"); -const { getLegosFor, networks } = require("@studydefi/money-legos"); - -const legos = getLegosFor(networks.mainnet); +const kyber = require("@studydefi/money-legos/kyber"); const provider = new ethers.providers.JsonRpcProvider( process.env.PROVIDER_URL || "http://localhost:8545", @@ -69,20 +67,16 @@ const swapOnKyber = async (fromAddress, toAddress, fromAmountWei) => { const minConversionRate = 1; const kyberNetwork = new ethers.Contract( - legos.kyber.contracts.network.address, - legos.kyber.contracts.factnetworkry.abi, + kyber.network.address, + kyber.network.abi, wallet, ); // ERC20 contract - const fromTokenContract = new ethers.Contract( - fromAddress, - legos.erc20.contracts.abi, - wallet, - ); + const fromTokenContract = new ethers.Contract(fromAddress, erc20.abi, wallet); // ETH -> Token - if (fromAddress === legos.erc20.contracts.eth.address) { + if (fromAddress === erc20.eth.address) { return kyberNetwork.swapEtherToToken(toAddress, minConversionRate, { gasLimit, value: fromAmountWei, @@ -93,7 +87,7 @@ const swapOnKyber = async (fromAddress, toAddress, fromAmountWei) => { await fromTokenContract.approve(kyberNetwork.address, fromAmountWei); // Token -> ETH - if (toAddress === legos.erc20.contracts.eth.address) { + if (toAddress === erc20.eth.address) { return fromExchangeContract.swapTokenToEther( fromAddress, fromAmountWei, @@ -125,7 +119,7 @@ const swapAndLog = async (fromToken, toToken, amount) => { ethers.utils.parseUnits(amount.toString(), fromToken.decimals), ); - if (toToken === legos.erc20.contracts.eth) { + if (toToken === erc20.eth) { const ethBalWei = await wallet.getBalance(); console.log( `${toToken.symbol} balance: ${ethers.utils.formatEther(ethBalWei)}`, @@ -145,9 +139,9 @@ const swapAndLog = async (fromToken, toToken, amount) => { }; const main = async () => { - await swapAndLog(legos.erc20.contracts.eth, legos.erc20.contracts.dai, 1); - await swapAndLog(legos.erc20.contracts.dai, legos.erc20.contracts.rep, 50); - await swapAndLog(legos.erc20.contracts.rep, legos.erc20.contracts.eth, 2); + await swapAndLog(erc20.eth, erc20.dai, 1); + await swapAndLog(erc20.dai, erc20.rep, 50); + await swapAndLog(erc20.rep, erc20.eth, 2); }; main(); diff --git a/src/idle/index.ts b/src/idle/index.ts index 643e2b6..57a2bd7 100644 --- a/src/idle/index.ts +++ b/src/idle/index.ts @@ -1,7 +1,7 @@ import { default as contracts } from "./contracts"; import abi from "./abi/IdleTokenV3.json"; -export default { +export = { ...contracts, abi, decimals: 18, diff --git a/src/kyber/index.ts b/src/kyber/index.ts index 0b557fa..e9a8a7a 100644 --- a/src/kyber/index.ts +++ b/src/kyber/index.ts @@ -1,5 +1,5 @@ import { default as contracts } from "./contracts"; -export default { +export = { ...contracts, }; From e0edb79bc738bd97db93b99fb89abcffcbce19fb Mon Sep 17 00:00:00 2001 From: Kris Urbas Date: Wed, 27 May 2020 17:02:18 +0200 Subject: [PATCH 2/2] fix example for kyber --- docs/kyber.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/kyber.md b/docs/kyber.md index b14f742..1280650 100644 --- a/docs/kyber.md +++ b/docs/kyber.md @@ -44,6 +44,7 @@ contract KyberNetworkProxy is KyberNetworkProxyInterface, SimpleNetworkInterface ```js const { ethers } = require("ethers"); +const erc20 = require("@studydefi/money-legos/erc20"); const kyber = require("@studydefi/money-legos/kyber"); const provider = new ethers.providers.JsonRpcProvider(