Skip to content

Commit

Permalink
Remove SwapProxy from contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
boczeratul committed Mar 24, 2021
1 parent fa816a4 commit f9ae36d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36 deletions.
11 changes: 2 additions & 9 deletions scripts/exchange/FusdUsdtSwapPair/addLiquidity.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FUSD from 0xFUSDADDRESS
import TeleportedTetherToken from 0xTELEPORTEDUSDTADDRESS
import FusdUsdtSwapPair from 0xFUSDUSDTSWAPPAIRADDRESS
import FusdUsdtSwapPairProxy from 0xFUSDUSDTSWAPPAIRADDRESS

transaction(token1Amount: UFix64, token2Amount: UFix64) {
// The Vault references that holds the tokens that are being transferred
let fusdVault: &FUSD.Vault
let tetherVault: &TeleportedTetherToken.Vault

// The proxy holder reference for access control
let swapProxyRef: &FusdUsdtSwapPairProxy.SwapProxy

// The Vault reference for liquidity tokens
let liquidityTokenRef: &FusdUsdtSwapPair.Vault

prepare(signer: AuthAccount, proxyHolder: AuthAccount) {
prepare(signer: AuthAccount) {
self.fusdVault = signer.borrow<&FUSD.Vault>(from: /storage/fusdVault)
?? panic("Could not borrow a reference to Vault")

Expand Down Expand Up @@ -43,9 +39,6 @@ transaction(token1Amount: UFix64, token2Amount: UFix64) {

self.liquidityTokenRef = signer.borrow<&FusdUsdtSwapPair.Vault>(from: FusdUsdtSwapPair.TokenStoragePath)
?? panic("Could not borrow a reference to Vault")

self.swapProxyRef = proxyHolder.borrow<&FusdUsdtSwapPairProxy.SwapProxy>(from: FusdUsdtSwapPairProxy.SwapProxyStoragePath)
?? panic("Could not borrow a reference to proxy holder")
}

execute {
Expand All @@ -55,7 +48,7 @@ transaction(token1Amount: UFix64, token2Amount: UFix64) {

// Provide liquidity and get liquidity provider tokens
let tokenBundle <- FusdUsdtSwapPair.createTokenBundle(fromToken1: <- token1Vault, fromToken2: <- token2Vault)
let liquidityTokenVault <- self.swapProxyRef.addLiquidity(from: <- tokenBundle)
let liquidityTokenVault <- FusdUsdtSwapPair.addLiquidity(from: <- tokenBundle)

// Keep the liquidity provider tokens
self.liquidityTokenRef.deposit(from: <- liquidityTokenVault)
Expand Down
11 changes: 2 additions & 9 deletions scripts/exchange/FusdUsdtSwapPair/removeLiquidity.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@ import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FUSD from 0xFUSDADDRESS
import TeleportedTetherToken from 0xTELEPORTEDUSDTADDRESS
import FusdUsdtSwapPair from 0xFUSDUSDTSWAPPAIRADDRESS
import FusdUsdtSwapPairProxy from 0xFUSDUSDTSWAPPAIRADDRESS

transaction(amount: UFix64, token1Amount: UFix64, token2Amount: UFix64) {
// The Vault reference for liquidity tokens that are being transferred
let liquidityTokenRef: &FusdUsdtSwapPair.Vault

// The proxy holder reference for access control
let swapProxyRef: &FusdUsdtSwapPairProxy.SwapProxy

// The Vault references to receive the liquidity tokens
let fusdVaultRef: &FUSD.Vault
let tetherVaultRef: &TeleportedTetherToken.Vault

prepare(signer: AuthAccount, proxyHolder: AuthAccount) {
prepare(signer: AuthAccount) {
assert(amount == token1Amount + token2Amount: "Incosistent liquidtiy amounts")

self.liquidityTokenRef = signer.borrow<&FusdUsdtSwapPair.Vault>(from: FusdUsdtSwapPair.TokenStoragePath)
?? panic("Could not borrow a reference to Vault")

self.swapProxyRef = proxyHolder.borrow<&FusdUsdtSwapPairProxy.SwapProxy>(from: FusdUsdtSwapPairProxy.SwapProxyStoragePath)
?? panic("Could not borrow a reference to proxy holder")

self.fusdVaultRef = signer.borrow<&FUSD.Vault>(from: /storage/fusdVault)
?? panic("Could not borrow a reference to Vault")

Expand All @@ -36,7 +29,7 @@ transaction(amount: UFix64, token1Amount: UFix64, token2Amount: UFix64) {
let liquidityTokenVault <- self.liquidityTokenRef.withdraw(amount: amount) as! @FusdUsdtSwapPair.Vault

// Take back liquidity
let tokenBundle <- self.swapProxyRef.removeLiquidity(from: <-liquidityTokenVault, token1Amount: token1Amount, token2Amount: token2Amount)
let tokenBundle <- FusdUsdtSwapPair.removeLiquidity(from: <-liquidityTokenVault, token1Amount: token1Amount, token2Amount: token2Amount)

// Deposit liquidity tokens
self.fusdVaultRef.deposit(from: <- tokenBundle.withdrawToken1())
Expand Down
11 changes: 2 additions & 9 deletions scripts/exchange/FusdUsdtSwapPair/swapFusdForUsdt.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FUSD from 0xFUSDADDRESS
import TeleportedTetherToken from 0xTELEPORTEDUSDTADDRESS
import FusdUsdtSwapPair from 0xFUSDUSDTSWAPPAIRADDRESS
import FusdUsdtSwapPairProxy from 0xFUSDUSDTSWAPPAIRADDRESS

transaction(amountIn: UFix64) {
// The Vault references that holds the tokens that are being transferred
let fusdVault: &FUSD.Vault
let tetherVault: &TeleportedTetherToken.Vault

// The proxy holder reference for access control
let swapProxyRef: &FusdUsdtSwapPairProxy.SwapProxy

prepare(signer: AuthAccount, proxyHolder: AuthAccount) {
prepare(signer: AuthAccount) {
self.fusdVault = signer.borrow<&FUSD.Vault>(from: /storage/fusdVault)
?? panic("Could not borrow a reference to FUSD Vault")

Expand All @@ -37,15 +33,12 @@ transaction(amountIn: UFix64) {

self.tetherVault = signer.borrow<&TeleportedTetherToken.Vault>(from: TeleportedTetherToken.TokenStoragePath)
?? panic("Could not borrow a reference to tUSDT Vault")

self.swapProxyRef = proxyHolder.borrow<&FusdUsdtSwapPairProxy.SwapProxy>(from: FusdUsdtSwapPairProxy.SwapProxyStoragePath)
?? panic("Could not borrow a reference to proxy holder")
}

execute {
let token1Vault <- self.fusdVault.withdraw(amount: amountIn) as! @FUSD.Vault

let token2Vault <- self.swapProxyRef.swapToken1ForToken2(from: <-token1Vault)
let token2Vault <- FusdUsdtSwapPair.swapToken1ForToken2(from: <-token1Vault)

self.tetherVault.deposit(from: <- token2Vault)
}
Expand Down
11 changes: 2 additions & 9 deletions scripts/exchange/FusdUsdtSwapPair/swapUsdtForFusd.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import FungibleToken from 0xFUNGIBLETOKENADDRESS
import FUSD from 0xFUSDADDRESS
import TeleportedTetherToken from 0xTELEPORTEDUSDTADDRESS
import FusdUsdtSwapPair from 0xFUSDUSDTSWAPPAIRADDRESS
import FusdUsdtSwapPairProxy from 0xFUSDUSDTSWAPPAIRADDRESS

transaction(amountIn: UFix64) {
// The Vault references that holds the tokens that are being transferred
let fusdVault: &FUSD.Vault
let tetherVault: &TeleportedTetherToken.Vault

// The proxy holder reference for access control
let swapProxyRef: &FusdUsdtSwapPairProxy.SwapProxy

prepare(signer: AuthAccount, proxyHolder: AuthAccount) {
prepare(signer: AuthAccount) {
self.tetherVault = signer.borrow<&TeleportedTetherToken.Vault>(from: TeleportedTetherToken.TokenStoragePath)
?? panic("Could not borrow a reference to tUSDT Vault")

Expand All @@ -37,15 +33,12 @@ transaction(amountIn: UFix64) {

self.fusdVault = signer.borrow<&FUSD.Vault>(from: /storage/fusdVault)
?? panic("Could not borrow a reference to FUSD Vault")

self.swapProxyRef = proxyHolder.borrow<&FusdUsdtSwapPairProxy.SwapProxy>(from: FusdUsdtSwapPairProxy.SwapProxyStoragePath)
?? panic("Could not borrow a reference to proxy holder")
}

execute {
let token2Vault <- tetherVault.withdraw(amount: amountIn) as! @TeleportedTetherToken.Vault

let token1Vault <- self.swapProxyRef.swapToken2ForToken1(from: <-token2Vault)
let token1Vault <- FusdUsdtSwapPair.swapToken2ForToken1(from: <-token2Vault)

self.fusdVault.deposit(from: <- token1Vault)
}
Expand Down

0 comments on commit f9ae36d

Please sign in to comment.