@@ -13,7 +13,13 @@ import { BatchRequest, sendBatchRequest } from '../batch'
1313import { APIS , BASIS , CHAIN_VERSIONS , Network , WSS , ZILSWAPV2_CONTRACTS , ZIL_HASH } from '../constants'
1414import { isLocalStorageAvailable , toPositiveQa , unitlessBigNumber } from '../utils'
1515import { OnStateUpdate , Zilo } from '../zilo'
16- import { compile , LONG_ALPHA , PRECISION , SHORT_ALPHA } from './utils'
16+ import { LONG_ALPHA , PRECISION , SHORT_ALPHA } from './utils'
17+
18+ import POOL_CODE from "./contracts/ZilSwapPool.scilla"
19+
20+ declare module '*.scilla' { }
21+
22+ export { Network }
1723
1824BigNumber . config ( { EXPONENTIAL_AT : 1e9 } ) // never!
1925
@@ -116,7 +122,7 @@ export type Pool = {
116122 token1vReserve : BigNumber
117123
118124 exchangeRate : BigNumber // the zero slippage exchange rate
119- totalContribution : BigNumber
125+ totalSupply : BigNumber
120126
121127 contractState : PoolState
122128}
@@ -304,7 +310,6 @@ export class ZilSwapV2 {
304310 const name = `ZilSwap V2 ${ pair } LP Token`
305311 const symbol = `ZWAPv2LP.${ pair } `
306312
307- const file = `./src/zilswap-v2/contracts/ZilSwapPool.scilla`
308313 const init = [
309314 this . param ( '_scilla_version' , 'Uint32' , '0' ) ,
310315 this . param ( 'init_token0' , 'ByStr20' , token0Hash ) ,
@@ -319,7 +324,7 @@ export class ZilSwapV2 {
319324 ] ;
320325
321326 // Deploy pool
322- const pool = await this . deployContract ( file , init )
327+ const pool = await this . deployPoolContract ( init )
323328
324329 // Add pool
325330 const tx = await this . addPool ( pool . address ! . toLowerCase ( ) )
@@ -358,7 +363,6 @@ export class ZilSwapV2 {
358363 const name = `ZilSwap V2 ${ pair } LP Token`
359364 const symbol = `ZWAPv2LP.${ pair } `
360365
361- const file = `./src/zilswap-v2/contracts/ZilSwapPool.scilla`
362366 const init = [
363367 this . param ( '_scilla_version' , 'Uint32' , '0' ) ,
364368 this . param ( 'init_token0' , 'ByStr20' , token0Hash ) ,
@@ -373,7 +377,7 @@ export class ZilSwapV2 {
373377 ] ;
374378
375379 // Call deployContract
376- const pool = await this . deployContract ( file , init )
380+ const pool = await this . deployPoolContract ( init )
377381 return pool
378382 }
379383
@@ -1723,11 +1727,10 @@ export class ZilSwapV2 {
17231727 return expectedAmount . toString ( )
17241728 }
17251729
1726- private async deployContract ( file : string , init : Value [ ] ) {
1730+ private async deployPoolContract ( init : Value [ ] ) {
17271731 console . log ( "Deploying ZilSwapV2Pool..." )
17281732 console . log ( init )
1729- const code = await compile ( file )
1730- const contract = this . zilliqa . contracts . new ( code , init )
1733+ const contract = this . zilliqa . contracts . new ( POOL_CODE , init )
17311734 const [ deployTx , state ] = await contract . deployWithoutConfirm ( this . _txParams , false )
17321735
17331736 // Check for txn acceptance
@@ -1746,7 +1749,7 @@ export class ZilSwapV2 {
17461749 const errorMsgList = errors [ depth ] . map ( ( num : any ) => TransactionError [ num ] )
17471750 return { ...acc , [ depth ] : errorMsgList }
17481751 } , { } ) )
1749- const error = `Failed to deploy contract at ${ file } ! \n${ errMsgs } `
1752+ const error = `Failed to deploy contract\n${ errMsgs } `
17501753 throw new Error ( error )
17511754 }
17521755
@@ -1844,9 +1847,9 @@ export class ZilSwapV2 {
18441847 let bestPath : [ Pool , boolean ] [ ] | null = null ;
18451848 for ( const pool of optionPools ) {
18461849 const isSameOrder = pool . contractState . token0 === tokenInHash ;
1847- const newPath = swapPath . concat ( [ pool , isSameOrder ] ) ;
1850+ const newPath = swapPath . concat ( [ [ pool , isSameOrder ] ] ) ;
18481851 const [ poolTokenIn , poolTokenOut ] = isSameOrder ? [ pool . contractState . token0 , pool . contractState . token1 ] : [ pool . contractState . token1 , pool . contractState . token0 ] ;
1849- const foundEndPool = poolTokenOut ! == tokenOutHash ;
1852+ const foundEndPool = poolTokenOut = == tokenOutHash ;
18501853
18511854 if ( ! foundEndPool && poolStepsLeft - 1 <= 0 ) {
18521855 continue ;
@@ -1859,7 +1862,6 @@ export class ZilSwapV2 {
18591862 bestPath = newPath ;
18601863 bestAmount = expAmount ;
18611864 }
1862- // else ignore
18631865 } else {
18641866 const { swapPath, expectedAmount } = this . findSwapPathIn ( newPath , poolTokenOut , tokenOutHash , expAmount , poolStepsLeft - 1 ) ;
18651867 if ( swapPath && expectedAmount . gt ( bestAmount ) ) {
@@ -1869,6 +1871,8 @@ export class ZilSwapV2 {
18691871 }
18701872 }
18711873
1874+ console . log ( "xx path" , bestPath , bestAmount . toString ( 10 ) )
1875+
18721876 return { swapPath : bestPath , expectedAmount : bestAmount } ;
18731877 }
18741878
@@ -1899,7 +1903,7 @@ export class ZilSwapV2 {
18991903 bestPath = newPath ;
19001904 bestAmount = expAmount ;
19011905 }
1902- // else ignore
1906+ break ;
19031907 } else {
19041908 const { swapPath, expectedAmount } = this . findSwapPathOut ( newPath , tokenInHash , poolTokenIn , expAmount , poolStepsLeft - 1 ) ;
19051909 if ( swapPath && expectedAmount . lt ( bestAmount ) ) {
@@ -2386,7 +2390,7 @@ export class ZilSwapV2 {
23862390 const token0vReserve = new BigNumber ( poolState . v_reserve0 )
23872391 const token1vReserve = new BigNumber ( poolState . v_reserve1 )
23882392 const exchangeRate = token0Reserve . times ( ampBps ) . dividedBy ( token1Reserve ) // token0/ token1
2389- const totalContribution = new BigNumber ( poolState . total_supply )
2393+ const totalSupply = new BigNumber ( poolState . total_supply )
23902394
23912395 const pool : Pool = {
23922396 poolAddress : toBech32Address ( poolHash ) ,
@@ -2401,7 +2405,7 @@ export class ZilSwapV2 {
24012405 token0vReserve,
24022406 token1vReserve,
24032407 exchangeRate,
2404- totalContribution ,
2408+ totalSupply ,
24052409
24062410 contractState : poolState ,
24072411 } ;
0 commit comments