Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
427 changes: 181 additions & 246 deletions cadence/contracts/FlowYieldVaultsEVM.cdc

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions cadence/scripts/admin/get_allowlist_status.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,39 @@ access(all) fun main(contractAddress: String, addressToCheck: String): Allowlist
let fromAddress = EVM.addressFromString("0x0000000000000000000000000000000000000001")

// Read allowlistEnabled
let enabledCalldata = EVM.encodeABIWithSignature("allowlistEnabled()", [])
let enabledResult = EVM.dryCall(
let enabledResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: enabledCalldata,
signature: "allowlistEnabled()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>()]
)

var enabled = false
if enabledResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: enabledResult.data)
enabled = decoded[0] as! Bool
assert(enabledResult.results.length == 1, message: "Invalid response from allowlistEnabled()")
enabled = enabledResult.results[0] as! Bool
}

// Check if address is allowlisted (if provided)
var isAllowlisted = false
if addressToCheck.length > 0 {
let checkAddress = EVM.addressFromString(addressToCheck)
let allowlistedCalldata = EVM.encodeABIWithSignature("allowlisted(address)", [checkAddress])
let allowlistedResult = EVM.dryCall(
let allowlistedResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: allowlistedCalldata,
signature: "allowlisted(address)",
args: [checkAddress],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>()]
)

if allowlistedResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: allowlistedResult.data)
isAllowlisted = decoded[0] as! Bool
assert(allowlistedResult.results.length == 1, message: "Invalid response from allowlisted()")
isAllowlisted = allowlistedResult.results[0] as! Bool
}
}

Expand Down
26 changes: 14 additions & 12 deletions cadence/scripts/admin/get_blocklist_status.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,39 @@ access(all) fun main(contractAddress: String, addressToCheck: String): Blocklist
let fromAddress = EVM.addressFromString("0x0000000000000000000000000000000000000001")

// Read blocklistEnabled
let enabledCalldata = EVM.encodeABIWithSignature("blocklistEnabled()", [])
let enabledResult = EVM.dryCall(
let enabledResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: enabledCalldata,
signature: "blocklistEnabled()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>()]
)

var enabled = false
if enabledResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: enabledResult.data)
enabled = decoded[0] as! Bool
assert(enabledResult.results.length == 1, message: "Invalid response from blocklistEnabled()")
enabled = enabledResult.results[0] as! Bool
}

// Check if address is blocklisted (if provided)
var isBlocklisted = false
if addressToCheck.length > 0 {
let checkAddress = EVM.addressFromString(addressToCheck)
let blocklistedCalldata = EVM.encodeABIWithSignature("blocklisted(address)", [checkAddress])
let blocklistedResult = EVM.dryCall(
let blocklistedResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: blocklistedCalldata,
signature: "blocklisted(address)",
args: [checkAddress],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>()]
)

if blocklistedResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: blocklistedResult.data)
isBlocklisted = decoded[0] as! Bool
assert(blocklistedResult.results.length == 1, message: "Invalid response from blocklisted()")
isBlocklisted = blocklistedResult.results[0] as! Bool
}
}

Expand Down
65 changes: 35 additions & 30 deletions cadence/scripts/admin/get_evm_contract_config.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -39,77 +39,82 @@ access(all) fun main(contractAddress: String): EVMContractConfig {

// Read authorizedCOA
var authorizedCOA = ""
let coaCalldata = EVM.encodeABIWithSignature("authorizedCOA()", [])
let coaResult = EVM.dryCall(
let coaResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: coaCalldata,
signature: "authorizedCOA()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<EVM.EVMAddress>()]
)
if coaResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<EVM.EVMAddress>()], data: coaResult.data)
authorizedCOA = (decoded[0] as! EVM.EVMAddress).toString()
assert(coaResult.results.length == 1, message: "Invalid response from authorizedCOA()")
authorizedCOA = (coaResult.results[0] as! EVM.EVMAddress).toString()
}

// Read allowlistEnabled
var allowlistEnabled = false
let allowlistCalldata = EVM.encodeABIWithSignature("allowlistEnabled()", [])
let allowlistResult = EVM.dryCall(
let allowlistResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: allowlistCalldata,
signature: "allowlistEnabled()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>()]
)
if allowlistResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: allowlistResult.data)
allowlistEnabled = decoded[0] as! Bool
assert(allowlistResult.results.length == 1, message: "Invalid response from allowlistEnabled()")
allowlistEnabled = allowlistResult.results[0] as! Bool
}

// Read blocklistEnabled
var blocklistEnabled = false
let blocklistCalldata = EVM.encodeABIWithSignature("blocklistEnabled()", [])
let blocklistResult = EVM.dryCall(
let blocklistResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: blocklistCalldata,
signature: "blocklistEnabled()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>()]
)
if blocklistResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<Bool>()], data: blocklistResult.data)
blocklistEnabled = decoded[0] as! Bool
assert(blocklistResult.results.length == 1, message: "Invalid response from blocklistEnabled()")
blocklistEnabled = blocklistResult.results[0] as! Bool
}

// Read maxPendingRequestsPerUser
var maxPendingRequestsPerUser: UInt256 = 0
let maxCalldata = EVM.encodeABIWithSignature("maxPendingRequestsPerUser()", [])
let maxResult = EVM.dryCall(
let maxResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: maxCalldata,
signature: "maxPendingRequestsPerUser()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<UInt256>()]
)
if maxResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: maxResult.data)
maxPendingRequestsPerUser = decoded[0] as! UInt256
assert(maxResult.results.length == 1, message: "Invalid response from maxPendingRequestsPerUser()")
maxPendingRequestsPerUser = maxResult.results[0] as! UInt256
}

// Read getPendingRequestCount
var pendingRequestCount: UInt256 = 0
let countCalldata = EVM.encodeABIWithSignature("getPendingRequestCount()", [])
let countResult = EVM.dryCall(
let countResult = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: countCalldata,
signature: "getPendingRequestCount()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<UInt256>()]
)
if countResult.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: countResult.data)
pendingRequestCount = decoded[0] as! UInt256
assert(countResult.results.length == 1, message: "Invalid response from getPendingRequestCount()")
pendingRequestCount = countResult.results[0] as! UInt256
}

return EVMContractConfig(
Expand Down
16 changes: 7 additions & 9 deletions cadence/scripts/admin/get_evm_yieldvaults_for_user.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ access(all) fun main(contractAddress: String, userAddress: String): [UInt64] {
let evmUserAddress = EVM.addressFromString(userAddress)

// Read getYieldVaultIdsForUser(address)
let calldata = EVM.encodeABIWithSignature(
"getYieldVaultIdsForUser(address)",
[evmUserAddress]
)
let result = EVM.dryCall(
let result = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: calldata,
signature: "getYieldVaultIdsForUser(address)",
args: [evmUserAddress],
gasLimit: 500_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<[UInt64]>()]
)

if result.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<[UInt64]>()], data: result.data)
return decoded[0] as! [UInt64]
assert(result.results.length == 1, message: "Invalid response from getYieldVaultIdsForUser()")
return result.results[0] as! [UInt64]
}

return []
Expand Down
20 changes: 9 additions & 11 deletions cadence/scripts/admin/get_token_config.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@ access(all) fun main(contractAddress: String, tokenAddress: String): TokenConfig
let evmTokenAddress = EVM.addressFromString(tokenAddress)

// Read allowedTokens(address)
let calldata = EVM.encodeABIWithSignature("allowedTokens(address)", [evmTokenAddress])
let result = EVM.dryCall(
let result = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: calldata,
signature: "allowedTokens(address)",
args: [evmTokenAddress],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<Bool>(), Type<UInt256>(), Type<Bool>()]
)

var isSupported = false
var minimumBalance: UInt256 = 0
var isNative = false

if result.status == EVM.Status.successful {
let decoded = EVM.decodeABI(
types: [Type<Bool>(), Type<UInt256>(), Type<Bool>()],
data: result.data
)
isSupported = decoded[0] as! Bool
minimumBalance = decoded[1] as! UInt256
isNative = decoded[2] as! Bool
assert(result.results.length == 3, message: "Invalid response from allowedTokens()")
isSupported = result.results[0] as! Bool
minimumBalance = result.results[1] as! UInt256
isNative = result.results[2] as! Bool
}

return TokenConfig(
Expand Down
16 changes: 7 additions & 9 deletions cadence/scripts/admin/get_user_pending_balance.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ access(all) fun main(contractAddress: String, userAddress: String, tokenAddress:
let evmTokenAddress = EVM.addressFromString(tokenAddress)

// Read getUserPendingBalance(address, address)
let calldata = EVM.encodeABIWithSignature(
"getUserPendingBalance(address,address)",
[evmUserAddress, evmTokenAddress]
)
let result = EVM.dryCall(
let result = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: calldata,
signature: "getUserPendingBalance(address,address)",
args: [evmUserAddress, evmTokenAddress],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<UInt256>()]
)

if result.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: result.data)
return decoded[0] as! UInt256
assert(result.results.length == 1, message: "Invalid response from getUserPendingBalance()")
return result.results[0] as! UInt256
}

return 0
Expand Down
16 changes: 7 additions & 9 deletions cadence/scripts/admin/get_user_pending_request_count.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ access(all) fun main(contractAddress: String, userAddress: String): UInt256 {
let evmUserAddress = EVM.addressFromString(userAddress)

// Read getUserPendingRequestCount(address)
let calldata = EVM.encodeABIWithSignature(
"getUserPendingRequestCount(address)",
[evmUserAddress]
)
let result = EVM.dryCall(
let result = EVM.dryCallWithSigAndArgs(
from: fromAddress,
to: evmContractAddress,
data: calldata,
signature: "getUserPendingRequestCount(address)",
args: [evmUserAddress],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: [Type<UInt256>()]
)

if result.status == EVM.Status.successful {
let decoded = EVM.decodeABI(types: [Type<UInt256>()], data: result.data)
return decoded[0] as! UInt256
assert(result.results.length == 1, message: "Invalid response from getUserPendingRequestCount()")
return result.results[0] as! UInt256
}

return 0
Expand Down
13 changes: 5 additions & 8 deletions cadence/transactions/admin/accept_ownership.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ transaction(contractAddress: String) {
execute {
let evmAddress = EVM.addressFromString(contractAddress)

let calldata = EVM.encodeABIWithSignature(
"acceptOwnership()",
[]
)

let result = self.coa.call(
let result = self.coa.callWithSigAndArgs(
to: evmAddress,
data: calldata,
signature: "acceptOwnership()",
args: [],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: nil
)

assert(result.status == EVM.Status.successful, message: "acceptOwnership failed")
Expand Down
15 changes: 6 additions & 9 deletions cadence/transactions/approve_erc20_from_coa.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ transaction(tokenAddressHex: String, spenderAddressHex: String, amount: UInt256)
let tokenAddress = EVM.addressFromString(tokenAddressHex)
let spenderAddress = EVM.addressFromString(spenderAddressHex)

// Encode approve(address,uint256) call using EVM.encodeABIWithSignature
let calldata = EVM.encodeABIWithSignature(
"approve(address,uint256)",
[spenderAddress, amount]
)

let result = self.coa.call(
// Call the function approve(address,uint256)
let result = self.coa.callWithSigAndArgs(
to: tokenAddress,
data: calldata,
signature: "approve(address,uint256)",
args: [spenderAddress, amount],
gasLimit: 100_000,
value: EVM.Balance(attoflow: 0)
value: 0,
resultTypes: nil
)

assert(
Expand Down
Loading
Loading