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: add Erc20 contracts #2811

Merged
merged 30 commits into from
Jun 17, 2024
Merged

feat: add Erc20 contracts #2811

merged 30 commits into from
Jun 17, 2024

Conversation

0xverin
Copy link
Contributor

@0xverin 0xverin commented Jun 13, 2024

Context

resolves p-845
resolves p-846
This PR mainly implements the ERC20 contract on BSC and Ethereum networks.

Labels

Please apply following PR-related labels when appropriate:

  • C0-breaking: if your change could break the existing client, e.g. API change, critical logic change
  • C1-noteworthy: if your change is non-breaking, but is still worth noticing for the client, e.g. reference code improvement

How (Optional)

Testing Evidences

generate vc:

erc20(trx):

{
	context: ["https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/ed25519-2020/v1"],
	id: "0xdab1d8f33511e9ce4163fc39b069a7d1beed20d9cfb22819cacbe9287df7781c",
	types: [VerifiableCredential],
	credential_subject: CredentialSubject {
		id: "did:litentry:substrate:0x0000000000000000000000000000000000000000000000000000000000000000",
		description: "The amount of a particular token you are holding",
		types: "Token Holding Amount",
		assertion_text: "",
		data_source: None,
		assertions: [And {
			items: [Item {
				src: "$token",
				op: Equal,
				dst: "trx"
			}, Item {
				src: "$holding_amount",
				op: GreaterEq,
				dst: "1"
			}, Item {
				src: "$holding_amount",
				op: LessThan,
				dst: "50"
			}]
		}],
		values: [true],
		endpoint: ""
	},
	issuer: Issuer {
		id: "",
		name: "Litentry TEE Worker",
		mrenclave: "11111111111111111111111111111111",
		runtime_version: IssuerRuntimeVersion {
			parachain: 0,
			sidechain: 0
		}
	},
	issuance_date: "2024-06-13T12:22:46.826837967+00:00",
	parachain_block_number: 0,
	sidechain_block_number: 0,
	proof: None,
	credential_schema: CredentialSchema {
		id: "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-0.json",
		types: "JsonSchemaValidator2018"
	}
}

native token(bnb):

{
	context: ["https://www.w3.org/2018/credentials/v1", "https://w3id.org/security/suites/ed25519-2020/v1"],
	id: "0x8dc62b246d69406a82c1d2500904480299a1afccbca20b017b7ebb50dabe967e",
	types: [VerifiableCredential],
	credential_subject: CredentialSubject {
		id: "did:litentry:substrate:0x0000000000000000000000000000000000000000000000000000000000000000",
		description: "The amount of a particular token you are holding",
		types: "Token Holding Amount",
		assertion_text: "",
		data_source: None,
		assertions: [And {
			items: [Item {
				src: "$token",
				op: Equal,
				dst: "bnb"
			}, Item {
				src: "$holding_amount",
				op: GreaterEq,
				dst: "1"
			}, Item {
				src: "$holding_amount",
				op: LessThan,
				dst: "50"
			}]
		}],
		values: [true],
		endpoint: ""
	},
	issuer: Issuer {
		id: "",
		name: "Litentry TEE Worker",
		mrenclave: "11111111111111111111111111111111",
		runtime_version: IssuerRuntimeVersion {
			parachain: 0,
			sidechain: 0
		}
	},
	issuance_date: "2024-06-13T12:22:46.834042701+00:00",
	parachain_block_number: 0,
	sidechain_block_number: 0,
	proof: None,
	credential_schema: CredentialSchema {
		id: "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-0.json",
		types: "JsonSchemaValidator2018"
	}
}

TODO: Add all tokens.
All tokens have been added, reference from rust code.

Copy link

linear bot commented Jun 13, 2024

@0xverin 0xverin requested review from a team, kziemianek and higherordertech June 13, 2024 12:54
@Kailai-Wang
Copy link
Collaborator

I browsed the whole structure, it seems to be well desigend and made, nicely done

We'll need @kziemianek and @higherordertech to check more details 🙌

return (false, 0);
}
}
function getTokenBalance(
Copy link
Member

Choose a reason for hiding this comment

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

I wanted it to have 1 function per 1 rpc method but that's fine too.

Copy link
Contributor Author

@0xverin 0xverin Jun 14, 2024

Choose a reason for hiding this comment

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

It is not very convenient to use externally, and requires a lot of if statements, so I merged them here.

@kziemianek
Copy link
Member

kziemianek commented Jun 14, 2024

Can this be further simplified with #2812 ?
If yes then please wait for #2812 to be merged first.

@0xverin 0xverin force-pushed the token-holding-amount branch from 2941a9f to 224926a Compare June 17, 2024 10:07
@0xverin 0xverin merged commit 2b51405 into dev Jun 17, 2024
33 checks passed
@0xverin 0xverin deleted the token-holding-amount branch June 17, 2024 12:18
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

Successfully merging this pull request may close these issues.

3 participants