Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.

Add pack contract implementation #469

Merged
merged 15 commits into from
Jun 15, 2022
Merged

Add pack contract implementation #469

merged 15 commits into from
Jun 15, 2022

Conversation

adam-maj
Copy link
Contributor

No description provided.

@lgtm-com
Copy link

lgtm-com bot commented Jun 14, 2022

This pull request introduces 1 alert when merging 652539b into ca4b84d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Jun 14, 2022

This pull request introduces 1 alert when merging 4d41d0e into ca4b84d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

private contractWrapper: ContractWrapper<PackContract>;
private storage: IStorage;
static schema = PackContractSchema;
// TODO: Change schema and deployment
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops just forgot to remove the comment

throw new Error(
`ERC20 token with contract address "${
erc20.contractAddress
}" does not have enough allowance to transfer.\n\nYou can set allowance to the multiwrap contract to transfer these tokens by running:\n\nawait sdk.getToken("${
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lotthe conversion to Token contract struc and all the allowance checking logic could be shared between MW and pack no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some key differences because of the pack interface we want vs the one the contract implements, we need to do some multiplication/division in all these in the pack file that's different for each function in pack + different from multiwrap - which is why I opted to keep these all separate as verbose as it is, b/c handling all the casing seems messier and wanted to keep things explicit.

TL;DR, because contract uses total tokens + number of rewards (division), but we use tokens per reward + number of rewards (multiplication) we have to do some conversions between these interfaces which makes things different from MW and each other.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see - that makes sense.

Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, minor things - mainly trying to avoid some code duplication if we can. Though the API reads pretty nice right now

const ERC20RewardSchema = ERC20WrappableSchema.omit({
quantity: true,
}).extend({
quantityPerReward: PriceSchema,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonder if it's really worth it to rename this. would help with code sharing if we didnt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think quantityPerReward is an important distinction here - added it because I originally had just quantity as the interface, but when I was using it, it felt like quantity was the number of tokens I was going to wrap (which it isn't), so it felt confusing. What I had in mind was wouldn't want to have a user put something like:

quantity: 1
totalRewards: 50

expecting to only lose 1 token, and then lose 50, so wanted to make it explicit.

export const PackRewardsOutputSchema = z.object({
erc20Rewards: z.array(ERC20RewardContentsSchema).default([]),
erc721Rewards: z.array(ERC721RewardContentsSchema).default([]),
erc1155Rewards: z.array(ERC1155RewardContentsSchema).default([]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this - erc20Contents would make sense in both the pack and MW context right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema is a bit different for rewards vs MW because of the amounts stuff

tokenId: "2",
amount: BigNumber.from(50),
quantityPerReward: 1,
totalRewards: 50,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does read kinda nice though

tokenId: "2",
amount: BigNumber.from(50),
quantityPerReward: 1,
totalRewards: 50,
},
],
metadata: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call this "packMetadata" to be clear its for the pack?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep good idea, maybe should to something similar for MW

* // The address of the contract that holds the rewards you want to include
* assetContract: "0x...",
* // The metadata of the pack
* const packMetadata = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would call this pack and metadata -> packMetadata

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the example after the metadata rename?

* Create Pack
* @remarks Create a new pack with the given metadata and rewards and mint it to the connected wallet.
*
* @param metadataWithRewards - the metadata and rewards to include in the pack
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a See {@link Pack.createTo} in the remarks

* // The address of the contract that holds the rewards you want to include
* assetContract: "0x...",
* // The metadata of the pack
* const packMetadata = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the example after the metadata rename?

Copy link
Member

@joaquim-verges joaquim-verges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ship it!

@adam-maj adam-maj merged commit 217d7c7 into main Jun 15, 2022
@adam-maj adam-maj deleted the am/pack branch June 15, 2022 17:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants