Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: trait-flash-loan-user.flash-loan-user-trait implements (execute (<ft-trait> uint (optional (buff 16))) (response bool uint)) #353

Closed
fiftyeightandeight opened this issue Nov 16, 2021 · 2 comments
Assignees

Comments

@fiftyeightandeight
Copy link
Contributor

fiftyeightandeight commented Nov 16, 2021

Those contracts implementing trait-flash-loan-user (e.g. flash-loan-user-margin-usda-wbtc.clar) should then convert (optional (buff 16)) into uint using the following:

(define-read-only (buff-to-uint (bytes (buff 16)))
	(+
		(match (element-at bytes u0) byte (byte-to-uint byte) u0)
		(match (element-at bytes u1) byte (* (byte-to-uint byte) u256) u0)
		(match (element-at bytes u2) byte (* (byte-to-uint byte) u65536) u0)
		(match (element-at bytes u3) byte (* (byte-to-uint byte) u16777216) u0)
		(match (element-at bytes u4) byte (* (byte-to-uint byte) u4294967296) u0)
		(match (element-at bytes u5) byte (* (byte-to-uint byte) u1099511627776) u0)
		(match (element-at bytes u6) byte (* (byte-to-uint byte) u281474976710656) u0)
		(match (element-at bytes u7) byte (* (byte-to-uint byte) u72057594037927936) u0)
		(match (element-at bytes u8) byte (* (byte-to-uint byte) u18446744073709551616) u0)
		(match (element-at bytes u9) byte (* (byte-to-uint byte) u4722366482869645213696) u0)
		(match (element-at bytes u10) byte (* (byte-to-uint byte) u1208925819614629174706176) u0)
		(match (element-at bytes u11) byte (* (byte-to-uint byte) u309485009821345068724781056) u0)
		(match (element-at bytes u12) byte (* (byte-to-uint byte) u79228162514264337593543950336) u0)
		(match (element-at bytes u13) byte (* (byte-to-uint byte) u20282409603651670423947251286016) u0)
		(match (element-at bytes u14) byte (* (byte-to-uint byte) u5192296858534827628530496329220096) u0)
		(match (element-at bytes u15) byte (* (byte-to-uint byte) u1329227995784915872903807060280344576) u0)
	)
)

flash-loan of alex-vault also needs to be updated (to pass (optional (buff 16))).

We also need a util / function to convert uint into (buff 16).

@fiftyeightandeight
Copy link
Contributor Author

(define-ready-only (uint-to-buff uint) should be implemented by reversing (buff-to-uint (bytes (buff 16)))

@SaadTahirTintash
Copy link
Contributor

flash-loan of alex-vault also needs to be updated (to pass (optional (buff 16))).

According to this comment, I understand that we need to change the flash-loan in trait-vault.clar from (optional memo) to (optional uint). But while I was checking the test case Flash Loan: create margin trade, the flash-loan function call is passing expiry as an argument to the function call flash-loan which accepts memo: number.

My question is then, do we need to change this .trait-vault flash-loan function signature? If yes then we have to pass expiry as a buffer. If not then we have to convert memo (optional uint) to (buff 16) and pass it in flash-loan-user execute method in alex-vault.clar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants